/** * Example of look-ahead for input streams. */ #include #include #include #include using namespace std; /** * Checks the stream to determine the type of each character until a newline * or EOF. */ void checkStream(istream &in) { bool stop=false; while(!in.eof() && !stop) { switch(in.peek()) { // Ignore whitespace case ' ': case '\t': case '\r': in.get(); // Actually remove character from stream break; // Set stop flag when newline is encountered case '\n': stop=true; in.get(); break; // Digits case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // peek() and get() return an int so you will need to // cast to a char if you want the symbol and not the // ASCII code printed cout<(in.get())<<" digit"<(in.get())<<" operator"<(in.get())<<" parenthesis"<