-
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 :)
-
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.
-
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.
-
Thanks you guys :)
EDIT: Nevermind, I should have looked in the tutorials for strings in the first place.
Thanks for all your help :)