Getline function returns nothing

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
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.
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
I figured it out, ios::app doesn't allow you to read the file.
Topic archived. No new replies allowed.