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 ?

Recommended Answers

All 2 Replies

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

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.

commented: Thanks for the clarification +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.