Thread: Do I really need enter?

  1. #1
    Unregistered
    Guest

    Do I really need enter?

    When using cin>> enter is needed to go on, is there a way so it just does it when the key is pressed?

    Thank you in advance
    Rasped

  2. #2
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Don't use cin...

    use

    getchar(character);

    use

    getche(character)

    use

    getch(character)

    for strings use

    getline(cin,string, terminator)

    where the terminator could be a '\n' newline (enter) or even a character like '#'

    or

    cin.getline(char_array, number to get, terminator)

    where the number to get is an integer value one less than your array size like 50 and terminator is like above.

    I guess it all depends on what you want to do. There are others as well....
    Blue

  3. #3
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    try this:
    ---------------------------------------
    string UsrInpt(int length){ // "length" = length of input
    string message = ""; //the input
    int x=0; // length count
    do{
    message+=getche(); // cancatente
    x++;
    }while(x!=length); // "message" has the same amount of character as "length"
    return (message);
    }
    ---------------------------------------
    This should let you enter an amount of inputs w/o enter.
    Yoshi

  4. #4
    Darrok
    Guest
    you could also read directly from the keyboard, but i forget how to do this, so i cant show you

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    Code:
    if (kbhit ()) return (getch ());
    else return (0);
    that way there's no waiting... however if you want the scan code as well i recommend writing code which calls an interrupt to get it... also, understanding the ways of the keyboard bufferred input scheme is quite helpful...
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  2. Assignment output help
    By Taka in forum C Programming
    Replies: 13
    Last Post: 09-23-2006, 11:40 PM
  3. endless loop for scanf - plz help
    By owi_just in forum C Programming
    Replies: 18
    Last Post: 03-20-2005, 01:41 PM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  5. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2003, 12:23 AM