Ofstream parameter problem.
Hi there,
I am trying to allow a user to choose the filename for a file which will hold data.
The data will be entered into the file with ofstream.
I started with this in my program:
Code:
char fileName[20]; //NO BOUNDS CHECKING!!!!
cout << "Enter the name of the .csv file" << endl;
cin >> fileName;
ofstream streamname(fileName);
Since there is no bounds checking, I tried to use a string:
Code:
string fileName;
cout << "Enter the name of the .csv file" << endl;
getline (cin, fileName);
ofstream streamname(fileName);
But (unless I was mistaken?) it seems ofstream cannot accept a string as a parameter.
So I tried this:
Code:
string tempfilename;
vector<string>fileName;
cout << "Enter the name of the .csv file" << endl;
getline (cin, tempfilename);
fileName.push_back(tempfilename);
ofstream streamname(fileName);
But then Visual Studio reports:
Quote:
cannot convert parameter 1 from 'std::vector<_Ty>' to 'const char *'
Could anyone advise me on how do this is as simply as possible?
Thanks for any help!