Thread: Getting multiple inputs using cin

  1. #1
    Registered User
    Join Date
    Sep 2001

    Getting multiple inputs using cin

    OK, so here's the deal. I'm writing a text-based program that accepts either single-character inputs, or multiple inputs from its own prompt. So, the following inputs are valid:

    PROGRAM_PROMPT>  d 20 3
    So, I'd like to be able to accept single-character, as well as single-character/int/int input. This should act kind of like command line arguments, but it's within the program. How do I go about doing this?
    liberate tutamet ex inferis

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Read a whole line into a char array (or a string), using say getline, then parse the string looking for keywords / parameters etc.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    int i
    int iVariable[ size ]
    char strVariable[ size ]

    while ( reading keyBoard and not eof )
    if ( strVariable is alpha ) continue
    iVariable [ i ] = alpha to interger strVariable
    } // end while

    There are better, more complicated ways. Try this first

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checking inputs meets multiple conditions
    By 60beetle60 in forum C Programming
    Replies: 5
    Last Post: 04-19-2008, 08:25 AM
  2. multiple instances of cin
    By Chaplin27 in forum C++ Programming
    Replies: 4
    Last Post: 10-08-2004, 04:51 PM
  3. multiple inputs of multiple types
    By frontz in forum C Programming
    Replies: 8
    Last Post: 01-19-2004, 02:57 PM
  4. Multiple variable cin line
    By Dark Nemesis in forum C++ Programming
    Replies: 3
    Last Post: 08-02-2003, 10:57 PM
  5. Multiple inputs with cin
    By DJPG5 in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2003, 04:10 PM