0

I am trying to edit a field as it is being input, not waiting for the <CR> using Microsoft VC

Borland will allow a "myChar = cin.get();" and will return the char immediately to program control. Microsoft insists that it must be followed by a <CR> before the program can see the character and provide an message.

How do I get Microsoft to get the character and return control to the program without waiting for a <CR> ? :rolleyes:

sample code

#include <iostream.h>

void main( )
{
    char myChar;
    int myInt = 0;

    cout << "Give me an integer: ";

    while ( ( myChar = cin.get( ) ) != '\n' )
    {
        if ( myChar < '0' || myChar > '9' )
            cout << "Bad char !!";               // Throw away illegal chars
        else
            {
                myChar = myChar - '0';
                myInt = myInt * 10 + myChar;
            }
    }
}

<< moderator edit: added [co[u][/u]de][/co[u][/u]de] tags >>

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by daybreak7
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.