Receiving integers, but also want to test for char.

Posted by Wayne Haworth on Stack Overflow See other posts from Stack Overflow or by Wayne Haworth
Published on 2010-05-29T11:15:26Z Indexed on 2010/05/29 11:22 UTC
Read the original article Hit count: 143

Filed under:

Say I am looking to receive a series of numeric values and read them into an int, but I also want to test if the user hit key 'x'.

I am sure I am missing something obvious, and have tried a few things but seem to be stuck.

This is what I have so far...
cout << endl << "Enter key (or 'x' to exit): ";
cin >> key;
if (key == 'x') { cout << "exiting";}
// continue on...

© Stack Overflow or respective owner

Related posts about c++