He is trying to iterate over and empty line.
You are better off just reading the line in its entirety, then reversing it.
1 2 3 4 5
|
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
|
1 2 3 4 5 6 7 8 9
|
void rstring( istream& ins )
{
string line;
while (getline( ins, line ))
{
reverse( line.begin(), line.end() );
display( line );
}
}
|
A few other things:
1. The
peek() function only returns the next character. It does not advance the stream.
2. Better to just parameterize on an
istream unless your function requires an
ifstream.
3. Don't forget your opening and closing braces. As you have it, lines 8 and 9 are the
while loop. Everything following is not. Indentation is important only for use
humans in C and C++.
4. Don't loop on
istream::
eof(). If there is an error in reading, you'll loop forever. Instead, code against
istream::
good(), as I did above. (The
getline() function returns the stream, which implicitly tests
good().)
5. Hmm... had to step away for a moment and I can't remember what I was going to write here. Something mildly helpful, I think...
Anyway, hope this helps.
[edit]
Oh, also, the
display() function should take a
const string&
as argument.