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 >>