1

how do i get a user input string for file input/upload to work?

int main()
{

string P = "";

cout << "Input Directery Example: \" C:\\Users\\mugen\\Desktop\\data.txt \" " << endl;

getline(cin, P);

ofstream fileOut(P);  //does not seem to read string "P" how do i get it to work


system("pause");
}

i don't have to overload "ofstream.open()" do it if so what is the definition for it...i haven't learned more then operation overload yet!!!

Votes + Comments
For using code tags on first post (+ indicating your problem very well) :) !!
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ArkM
0

> Try ofstream fileOut(P.c_str()); instead of ofstream fileOut(P); :) ...

> ofstream requires the filename to be passed as a const char* , the c_str() method from the string class will convert the string which contains the filename to a const char* and return it (the string itself remains intact) ...

0

Can you explain: why quotes in the prompt message? Did you want to delude a user? If he/she types the name with quotes (by example) you can't use it as a file path in open function...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.