Thread: Easy question

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    5

    Easy question

    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?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    5
    I can use conio.h...will you please explain how to use getch()?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    12
    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:

    Code:
    int x=getch(); 
    if (x==49) { cout<<"You Press number 1"; }
    else { cout<<"Nothing has entered": }
    the int x=getc() there will automatically get the value of x corresponds to your condition....
    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();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. easy Vector contructor question
    By noodle24 in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2006, 07:43 PM
  2. Another Embarassingly Easy Question
    By almo89 in forum C Programming
    Replies: 2
    Last Post: 02-11-2006, 04:59 PM
  3. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 01:36 AM
  4. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 10:43 PM
  5. Easy Question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-12-2002, 12:19 PM