Cannot compile fstream open method.
Hello,
I've a code starting like
1 2 3 4 5 6 7 8 9
|
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
(....)
|
And the g++ compiler, in GNU/Linux environment, when reach,
1 2 3 4 5
|
string ori_file;
ori_file = "./...";
(...)
fstream ent_file;
ent_file.open (ori_file, ios::in | ios::binary);
|
throws me this,
main.cc: In function ‘int main()’:
main.cc:167: error: no matching function for call to ‘std::basic_fstream<char, std::char_traits<char> >::open(std::string&, std::_Ios_Openmode)’
/usr/include/c++/4.3/fstream:756: note: candidates are: void std::basic_fstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
Why ? What am I doing wrong ???
S.
Last edited on
It doesn't take an std::string, it takes a const char*
ent_file.open(ori_file.c_str(), ios::in | ios::binary);
Thanks a lot,
Now works fine.
S.
Topic archived. No new replies allowed.