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:
Since there is no bounds checking, I tried to use a string:Code:char fileName[20]; //NO BOUNDS CHECKING!!!! cout << "Enter the name of the .csv file" << endl; cin >> fileName; ofstream streamname(fileName);
But (unless I was mistaken?) it seems ofstream cannot accept a string as a parameter.Code:string fileName; cout << "Enter the name of the .csv file" << endl; getline (cin, fileName); ofstream streamname(fileName);
So I tried this:
But then Visual Studio reports: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);
Could anyone advise me on how do this is as simply as possible?cannot convert parameter 1 from 'std::vector<_Ty>' to 'const char *'
Thanks for any help!