Thread: cin to array of chars

  1. #1
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004
    Posts
    49

    cin to array of chars

    Hello everyone,
    Im trying to scan in an several chars from the console using cin. The format will be one char sperated by a space. I want to put them in an array of chars. I dont want to have to hit return between each char.

    Example
    input-> Q Q Q Q C.

    Thanks
    Last edited by cdonlan; 02-25-2005 at 12:46 PM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    For 5 characters seperated by spaces the simplest way would likely be:

    Code:
    char array[5];
    cin >> array[0] >> array[1] >> array[2] >> array[3] >> array[4];
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modify an single passed array element
    By swgh in forum C Programming
    Replies: 3
    Last Post: 08-04-2007, 08:58 AM
  2. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  5. Array of pointers (chars)
    By Vber in forum C Programming
    Replies: 5
    Last Post: 02-08-2003, 04:29 AM