Getting multiple inputs using cin

This is a discussion on Getting multiple inputs using cin within the C++ Programming forums, part of the General Programming Boards category; OK, so here's the deal. I'm writing a text-based program that accepts either single-character inputs, or multiple inputs from its ...

  1. #1
    edk
    edk is offline
    Registered User
    Join Date
    Sep 2001
    Posts
    20

    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:

    Code:
    PROGRAM_PROMPT>  e
    
    ...and
    
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

    while ( reading keyBoard and not eof )
    {
    if ( strVariable is alpha ) continue
    else
    iVariable [ i ] = alpha to interger strVariable
    i++
    } // 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, 01: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, 03:10 PM

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