I cant understand why the following code wont work. When it gets to the getline stage, it doesn't wait for the prompt.
I'm running it in Microsoft visual c++ Express and the .h file includes iostream and fstream
However, if i change the order around - I.E i move the getline and cin around as the code below demonstrates - it all checks out ok and works.Code:#include "file.h" using namespace std; int main() { string file_location; string file_text; cout << "Where would you like to store your file" ; cin >> file_location; cout << endl; cout << "What would you like to write in your file"; getline(cin, file_text); ofstream fout(file_location); fout << file_text; fout.close(); }
Code:string file_location; string file_text; cout << "What would you like to write in your file"; getline(cin, file_text); cout << endl; cout << "Where would you like to store your file" ; cin >> file_location; ofstream fout(file_location); fout << file_text; fout.close();



LinkBack URL
About LinkBacks



