Thread: Another n00b question: storing text as a variable

  1. #1
    Registered User
    Join Date
    Jul 2007

    Another n00b question: storing text as a variable

    for my first game-type programming project, I'm going to try to make a simple text adventure that's only a few screens long. How can I make it so that the user can input text and it can be stored as a variable that affects the outcome, since char variables only store one character? is there some secret I'm missing? thanks for helping out a complete beginner!

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    The C way is to store text in char arrays that have a final character of '\0' to denote the end of the sequence of chars. This was messy if you didn't take heed that you handled them right. If you forgot a '\0' or you overran the buffer, you'd be in for some headaches. That's why C++ has the std::string class. It encapsulates the ugliness of storing text and manipulating it, and it's much safer to use.

    Google or check tutorials for information on std::string.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. A question about MacVim vs other text editors...
    By maccat in forum Tech Board
    Replies: 3
    Last Post: 02-04-2009, 05:17 AM
  3. File Reading and storing to 1 variable
    By Rare177 in forum C Programming
    Replies: 34
    Last Post: 07-13-2004, 12:58 PM
  4. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 04:11 AM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM