Dec 12, 2014 at 8:47am UTC
So I have this in my main function.
1 2 3 4 5 6 7 8 9
string input_string;
ifstream instream;
instream.open("document/document1_short.txt" , ios::app);
getline(instream, input_string, ' ' );
cout << "input_string: " << input_string << endl;
getline is supposed to record the first word in input_string and stop. But input_string contains nothing in cout.
Last edited on Dec 12, 2014 at 8:49am UTC
Dec 12, 2014 at 8:53am UTC
You should check to make sure the file opened properly. Also you are using a space as a delimiter, so if the first character happens to be a space, nothing will be input.
Dec 12, 2014 at 8:56am UTC
getline(instream, input_string);
The code above doesn't work either and I don't have first character as space.
You should check to make sure the file opened properly.
How do I do that?
instream.is_open()
returns true.
Last edited on Dec 12, 2014 at 9:04am UTC
Dec 12, 2014 at 9:14am UTC
I figured it out, ios::app
doesn't allow you to read the file.