How does one set a "cin" statement so that you don't have to press "enter" after entering? So that it takes the first character you enter automatically?
Printable View
How does one set a "cin" statement so that you don't have to press "enter" after entering? So that it takes the first character you enter automatically?
That is not possible.
It is often a good idea to alter your program so that you don't have to do that. However, if you want that functionality even without using cin, you must use non-standard console input functions. Whether any are available for you depends on your platform. Perhaps getch() from conio.h will work.
I can use conio.h...will you please explain how to use getch()?
getch() this is a function that would not terminate your program unless you press something on your keyboard....
if you'd like to use an automatic inputs i would suggest using getch(), for example:
the int x=getc() there will automatically get the value of x corresponds to your condition....Code:int x=getch();
if (x==49) { cout<<"You Press number 1"; }
else { cout<<"Nothing has entered": }
by the way in using this one.... if you enter number 1 into your keyboard.... in the computer 1 is equivalent to 49 , and 2 is 50.... for reference try this code and run it so that as you go along with your program you will not be wondering why does the number you entered doesn't corresponds to the computer:
Code:#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int x=getch();
cout<<x;
getch();
}