Thread: Storing Users Input

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    Storing Users Input

    Hello, I am quite new to C++ and I was wondering how to store a users input. I am thinking that I would use a string. I don't think I would use a string or a structure, unless their is a away to store input from a user into a structure. I am making a text based game right now, and I was wondering how to store users data. Ex. If I ask the user "how many cavalry units do you want?", I want to know how to store that data. THANKS.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Edit: I meant to say that I don't think that I would use a structure or an array. But I'm sure I would use a string. Help.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  3. #3
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Umm..

    Code:
    string cavalryUnits;
    
    cout << "how many cavalry units do you want? ";
    cin >> cavalryUnits;
    The entered value or whatever (value only should use an int, string if its text or something) is stored in cavalryUnits if you need to call it later.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    A structure is a good idea.

    With a structure, you can keep all of your data organized. This is especially true if...

    - Some of the variables in the structure can be integers, some floats, and some strings.

    - There are multiple users, and you need to store the same set of data for each user. With a structure, you can allow for any number of users, without knowing (when you write the program) how many users there will be.


    You will generally get one variable from the user at a time, and fill-in the structure as you go.

    Later when you learn about classes and objects you can "upgrade" the structure to a class (which is something like a smart structure).
    Last edited by DougDbug; 06-27-2005 at 06:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  3. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  4. reading data from the users input
    By SpEkTrE in forum C++ Programming
    Replies: 1
    Last Post: 04-10-2005, 06:15 PM
  5. Trouble storing file input in array
    By difficult.name in forum C Programming
    Replies: 1
    Last Post: 10-10-2004, 11:54 PM