I'm trying to take a file that has extra spaces in it, and correct it to eliminate each extra space and simply write one space between each word. The file data.dat contains this (with spaces explained since it automatically corrects it on here)-
This is (2 spaces) the (3 spaces) input (2 spaces) file.
My code seems to be skipping alternating words and produces
is input file. (spacing is correct)
I have the feeling im messing up in my getline declarations, but my code is:
You are calling getline() twice in your loop. Once at the beginning (41), and again at the end (47). You may also want to loop on simply !getline() since there could be an error reading the file that doesn't set the eof bit, and use next.empty() for your condition on line 43.