0

have a simple question about working with files . when Im reading a txt file like this example
Hello how are you.
fine thank you.
when I read it how can I find out there was an endline or not ?

3
Contributors
2
Replies
5
Views
4 Years
Discussion Span
Last Post by deceptikon
1

when I read it how can I find out there was an endline or not ?

How do you plan to use that information once you get it? That will somewhat determine what method you use. For example, you can run through the file character by character and look for '\n' to answer the simple question of whether a newline is present, but that may not be conducive to whatever you plan to do afterward.

Well if you use getline() it will read in everything in the file until it reaches a newline.

Until it reaches a newline or end-of-file (or an error occurs). So you'd need to check the stream state to be sure that the line ended with '\n' and not EOF.

Votes + Comments
Thanks for the clarification
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.