The problem is that you are prompting the user to enter a string of characters but you've declared pageName as a single char so it will only hold a single character and cin is only going to read the first character into it. The rest of what the user types will still be sitting in the input buffer waiting to be read. The next time cin is called it's not going to put a cursor to the screen to prompt for input. It will just read the next character from the buffer, and since there is nothing else to be done the program will just end.

Say I enter "index" for the pageName: the "i" will be read into pageName and then the next cout prompts will be put to the screen and the next cin will read the "n" of index into varifi and the program will terminate. The process happens so fast that you won't even see the second prompts on the screen before the window closes. One quick way to test if this is happening is run it again and enter a single character for the pageName and then see what happens.

One solution is to declare pageName as an array of chars with a maximum permissable size and then use cin.getline to read the entire string of characters into the pageName variable:

There is also a string object in C++ but I haven't used it since school, and I'm on vacation without any of my books handy. Anyway, if you're just starting out with C++ you usually start with strings as array of characters work your way up to using objects (at least we did in my C++ class).

hari

Born

Posts: 2

Loc: India

3+ Months Ago

For taking multiple characters as input, first declare the variable that holds the set of characters as a character array and then use the member function getline belonging to class cin. This will take the whole line as input and store it in the name variable.