I'm using dev-c++ and when I input characters into the code below, for example 'asdf', it loops fine. If I enter 'asdf(ctrl-z)' for end of file, program will output the asdf, but wont display cout << "eof reached" or exit the loop. If I enter ctrl-z by itself, program will output cout << "eof reached" and exit the loop. Can anyone point out what I'm doing wrong?
-I probably could do this better with a switch, that would be tomorrows exercise
-I probably could do this better with a switch, that would be tomorrows exercise
Rich (BB code):
#include <iostream>
using namespace std;
int main()
{
char temp;
char nwln = '\n';
cout << "EOF: " << EOF << endl;
cout << "Input something: ";
//while(nwln != temp)
do
{
temp = cin.get();
// cin >> temp;
if(temp != '\n' && temp != EOF) //cin.eof() )
cout << "You inputted:" << temp << "." << endl;
if(temp == '\n' )
cout << "New Line entered" << endl;
if(cin.eof() ) // if(temp == -1) // if(temp == EOF)
cout << "END OF FILE REACHED";
}while(!cin.eof() );
cout << "\n\n" ;
system("PAUSE");
}