My IDE is having issues with the “filename” variable on the last line. Can someone point out to me why?
switch(filename_selection)
{
case 1: filename_selection = 1;
filename = "foo3.sql";
break;
case 2: filename_selection = 2;
filename = "foo2.sql";
break;
case 3: filename_selection = 3;
filename = "foo1.sql";
break;
default:
cout << "Invalid selection." << endl;
break;
}
ofstream File;
File.open(filename, ios::out | ios::trunc);
My crystal ball is a bit cloudy today, but I think I can see something…
<psychic-powers>Your
filenameis declared asstd::string filename;. Sadly, in C++03,std::(i|o)fstreamclasses didn’t have constructors that acceptstd::stringvariables, onlychar const*ones.Solution: Pass
filename.c_str().</psychic-powers>