Thread: cin >>

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    18

    cin >>

    How would i put an amount of time that a user has to input something? Then use the if, else if and what not to determine what happens. Go by the system clock i assume? What function would that be?


    I want to make a trivia game where you only have a certain amount of time to answer, and u gain, or lose points depending on if your right or not.
    Last edited by TehClutchKiller; 06-05-2008 at 08:09 PM.

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    With standard function I don't know if you can.
    It certainly would be easier if you used event polling in SDL.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    it is not possible on the console without much ugly, complicated, and non-portable coding.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Save the time before the CIN, and after the CIN, get the current time. Take the difference in times. If the time took too long, no points.
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Dino's suggestion is a good and portable one. If you really want to read with timeout from the standard input, you're looking at non-portable, OS-specific solutions, and most likely, you will have to deal with the input processing (what to do with backspace, arrow keys and so on) as well.

    There is a FAQ called something like "How do I get input without the user hitting Enter?" which goes through a few of the different options of "reading input in raw mode". I have a feeling it also covers "has a key been pressed".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin >> string // multiple lines
    By msshapira in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2009, 04:39 AM
  2. if (cin >> a) {
    By manzoor in forum C++ Programming
    Replies: 1
    Last Post: 02-24-2008, 07:48 AM
  3. cin >> something
    By junkeat90 in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2008, 05:45 AM
  4. cin >> buf endless loop
    By cfriend in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2005, 04:01 PM
  5. cin >> char[]
    By Luigi in forum C++ Programming
    Replies: 3
    Last Post: 04-04-2003, 01:33 PM