another request sorry.. Right now I am reading the tokens in one by one and it works, but I want to know when there is a new line..
if my file contains
Hey Bob Now
should give me
Hey Bob [NEW LINE] NOW
Is there a way to do this without using getline?
Yes the operator>> when used with string read ‘white space’ separated words. A ‘White space’ includes space tab and new line characters.
If you want to read a line at a time use std::getline()
The line can then be tokenized separately with a string stream.
Small addition:
Without using getline()
So you really want to be able to detect a newline. This means that newline becomes another type of token. So lets assume that you have words separated by ‘white spaces’ as tokens and newline as its own token.
Then you can create a Token type.
Then all you have to do is write the stream operators for a token: