using getline

I understand that by using getline, I can capture multiple words in a string. What is NOT clicking for me is how to read a string from a text file up to the end of the line...

Say I have a text file that has multiple lines like this:
a aaa aaaa aa
b bbb bbbb bb
c ccc cccc cc

what is it in the getline function that signals the end of a line (carriage return)?
std::getline will by default read until a newline character. That's the default behavior. You have to specifically give it a different character to read until if you don't want that default behavior.
So all text on the next line is treated separately and requires a new call to getline?
It's not treated separately, it's just separated by a newline character.
So even though I can't see an end line in the text file, getline interprets the end of the text string as an end line character?
Andym wrote:
So even though I can't see an end line in the text file
Your text editor treats the newline character as a line separator and uses it to separate the lines. If you want to actually see the newline character, you should use a hex editor.
Last edited on
If you want to actually see the newline character, you should use a hex editor.
Or get a proper text editor and turn on display of whitespace characters: http://puu.sh/k6bTM/a0669b78aa.png
Last edited on
Topic archived. No new replies allowed.