Tutorialshare

Full Version: Read lines in c++
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to compare how many lines are the same in two .txt files. I was thinking on doing it by reading each line into a string and simple compare it, my question is... what's the best why to know where the line has ended? I want to read the invisible characters as well. I guess I could look for the enter ascii code but don't know how good of a idea is that.
That wouldn't be very efficient. In C++, cin can tell when enter is pressed for formatted input such as:
Code:
John Doe 100
Jane Doe 200

There is a function called get when used as cin.get() will get a character that is entered into the console program. It doesn't matter what the character is as it will get non printable characters (ie newline, tab, etc) as long as the console that is running the code is using the correct encoding (normally utf-8 which includes ASCII). A complicated input would be something like:
Code:
H2O
CO2

This is called scanning by the way and comes with another part called parsing which happens after reading the file.
Reference URL's