Hi, I am trying to create a program that will remove all of the extra whitespace in one file, and output the result to another file. My code thus far prints only the first letter of the original file. Any help you can provide would be greatly appreciated.
Thanks for the help. I modified moorecm's suggestion to add one space between each word. My only question is how would I include a "\n" or "endl" to start the second sentence in the file on a new line?
Do you just want to insert newlines or do you want to preserve the newlines as they were?
For the latter, you can try something like this:
1 2 3 4 5 6 7
while( getline( fin, s ) ) { // read a line at a time
stringstream line( s );
while( line >> s ) { // read the words, ignoring whitespace
fout << s;
}
fout << endl; // put the newline back
}