954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Read a single char using Microsoft VC 6 or NET

I am trying to edit a field as it is being input, not waiting for the 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 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 ? :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 [code][/code] tags >>

daybreak7
Newbie Poster
3 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 
daybreak7
Newbie Poster
3 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You