PDA

View Full Version : C++ File I/O



Yes
August 17th, 2007, 10:58 PM
Is it possible to open a file like this?


void openFile (string fileName)
{
fstream myfile;
myfile.open (fileName);
}

Because that's what I have now, and I keep getting a compilation error, "no matching function call for call to 'std::basic_fstream<char, std::char_traits<char> >::'open(std::string&)'".

Thanks.

Paul820
August 17th, 2007, 11:11 PM
It has to be a cstyle string, so it should be


myfile.open( filename.c_str() );

Yes
August 17th, 2007, 11:15 PM
Great, thank's!