On Nov 6, 3:23 pm, riva <ra.ravi....@gmail.comwrote:
#include <iostream>
using namespace std;
int main(void)
{
int i=0;
while(char c = cin.get() != EOF) {
i++;
cout << i << c << endl;
}
}
I am a C programmer and I am learning C++ from Thinking in C++.
The problems with the above code are:
1) i is incremented twice and the output is printed twice.
2) c is not printed.
And your question is?
You probably mean something like
while(
(c = std::cin.get()) != EOF
) { ... }
Without the parentheses, you compare std::cin.get() with EOF, and
assign the result of the comparison to c. Then, c will contain some
sort of boolean representation, which is usually not printable (\0,
\1, or whatever).