cin, but without pressing enter?

This is a discussion on cin, but without pressing enter? within the C++ Programming forums, part of the General Programming Boards category; Hello, I am new to C++. I use cin when ever I want the user to put something in. But ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Unhappy cin, but without pressing enter?

    Hello, I am new to C++.

    I use cin when ever I want the user to put something in.
    But when using cin after you enter your number you have to press ENTER. So my question is, how do you let the user put in one number then the program automaticly continues, without the user having to press ENTER?

    Thanks in advance, August.

    P.S. My compiler doesn't have <windows.h>
    Last edited by Queatrix; 04-08-2005 at 04:53 PM. Reason: Forgot line.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    Welcome to the boards!

    I believe conio.h contains the getch() function. getch returns a keypress hit by the user and it's a matter of determining the resulting value (make a program that displays the result of getch() and write down the values)

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I don't fully understand it.
    Could you give me an example?
    Last edited by Queatrix; 04-08-2005 at 05:16 PM. Reason: Deleted line

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    char choice;
    
    cout << "enter menu choice";
    
    choice = getch( );
    Last edited by The Brain; 04-08-2005 at 05:55 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Now I am confused,
    You have this in you'r code,
    Code:
    cout "enter menu choice";
    My compiler only likes it when I do it like this:
    Code:
    cout << "enter menu choice";
    But other than that it works great!

    Thanks!
    Last edited by Queatrix; 04-08-2005 at 05:36 PM. Reason: Forgot line

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If you're looking for "real time" action then a function called kbhit() (or something similar, was years since I last used it), also residing in conio.h unless I'm mistaken.
    Code:
    char Key;
    
    while(Looping)
    {
      Key = 0; //Clear it
    
      if(kbhit())
      {
        Key = getch();
      }
    
       ... //Do stuff with the char
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Quote Originally Posted by Cool-August
    Now I am confused,
    You have this in you'r code,
    Code:
    cout "enter menu choice";
    That won't compile, and the compiler will display an error.

    My compiler only likes it when I do it like this:
    Code:
    cout << "enter menu choice";
    !
    Mine too.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Help: Currency Converter
    By Ashfury in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 01:21 PM
  2. little help please.
    By Uber Fr0g in forum C Programming
    Replies: 24
    Last Post: 10-12-2005, 10:54 AM
  3. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2003, 12:23 AM
  4. help with switch statements
    By Wexy in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 05:44 PM
  5. help on pressing enter to continue
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2001, 12:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21