-2

i need in my loop get character in realtime and check it by conditions. If user press whatever except enter, program works fine. Can anyone help me ? thanks !

   while (read != '\n')
            {
                cout << "Enter character:\n";
                read = _getwch();
                if (read == '\n') {
                    cout << "You pressed : ENTER\n";
                }
                else {
                    cout << "Your character is: \"" << read << "\"\n\n";
                    read = '\0';
                }
            }
mathew92
  • 43
  • 3
  • 9

1 Answers1

-2

include

using namespace std;

int main()

{

cout << "Press the ENTER key";

if (cin.get() == '\n')

{
       cout << "Good job.\n";
}
else
{
       cout << "I meant ONLY the ENTER key... Oh well.\n";
}

return 0;

}

This code will help in detecting the ENTER key when pressed. Hope this helps you.

Community
  • 1
  • 1
Varun Moghe
  • 74
  • 2
  • 3
  • 12
  • This code detecting characters afters ENTER press ... but i need check char after pressed any button ... for example .. press 'f' and console print 'f' ... and when i press enter console print "enter" and program shut down – mathew92 Dec 13 '14 at 13:18