Thread: Question about variables

  1. #1
    Registered User
    Join Date
    Mar 2006

    Question about variables

    Hello. I am new to C++, but am really enjoying programming in it, and am loving the site's tutorials. But I have a question about variables. I know that char can hold the ascii code of a letter, but what do I do if I want to have more than one letter, like a whole word? For instance, in my experimental program, I have it set to go back to the menu if the user enters m, or exit the program if the user enters e. What would I do if I wanted them to enter "menu" or "exit" instead?

    I apologize if this has been asked and answered many times, I couldn't find the answer to it

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    New York
    You would have an array of characters. This is called a C-style string, or NULL-terminated string, because the last character is a NULL byte indicating the end of the string.

    In C++, you may also use STL's std::string class.

  3. #3
    Registered User
    Join Date
    Jan 2005
    In C++, you should learn the string class before learning C style strings despite the fact that many tutorials and books still teach them the other way around.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Thanks you guys

    EDIT: Nevermind, I should have looked in the tutorials for strings in the first place.

    Thanks for all your help
    Last edited by BongoBob; 03-01-2006 at 11:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 12:02 PM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  4. question about declaring global variables
    By Dag_ in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2005, 06:03 AM
  5. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM