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!!!

mvmalderen commented: For using code tags on first post (+ indicating your problem very well) :) !! +3

Recommended Answers

All 2 Replies

> 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) ...

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.