Search code examples
c++ifstream

C++: How can I look at the next character of a file I'm reading in to compare the characters?


I have to read from a file one character at a time (can't read it using a string!) and if I find a // then I must ignore everything until I get to the end of the line.


Solution

  • If you don't want to use a state machine, I note that the ifstream class has a peek() method that you could use to look-ahead one character without needing to get then put back