I'm simply trying to utilize the get and peek functions to process characters from a file. I'm sure there's a much more efficient way to do this but I just want to know why this wont work for me. I hit run, enter the file name but nothing happens. Doesn't the peek function check the next character without consuming it?
'ch' is a char, 'inFile' is an fstream object for input, 'in' is a string
This code reads and outputs the words on the first line.
Then it encounters the '\n' character and enters an infinite loop, because, as you rightly said, "Doesn't the peek function check the next character without consuming it?"
My file could contain any text, but I guess to give you a sample text:
I walked my dog to the park.
My dog's name is Spot.
My program should output that in one line. Is the reason why i get an infinite loop is because the stream extraction operator and peek function never consume the new line character? What could I use then so the program will jump to the next line?