M
mel smith
Hi
I am having a problem with a simple program I have written. To start to
learn how to deal with the string class in C++ I created the the following
function as part of a larger exercise.
string pizzaNS::getName()
{
string itsName;
cout << "Please enter your name" << endl;
getline(cin, itsName)
return itsName;
}
The program that this is part of can be run over and over by selecting Y
after each calculation it performs. The program is fine when this function
is commented out. However when this is part of the program it works first
time, but on subsequent tries the program does not pause to allow the user
to input a name. For example
Enter your name.
XXXXXX
Enter the number of pizzas you require
XXXXX
The Second time you can't enter your name.
Enter your Name.
Enter the number of pizzas you require.
XXXXXX
It doesn't pause for input. Can the string still have the previous value in
it despite going out of scope. Is this why it is skipped the second time
around.
The program is an unmanaged program written in VS2003.
Thanking you in advance.
Nifsmith
I am having a problem with a simple program I have written. To start to
learn how to deal with the string class in C++ I created the the following
function as part of a larger exercise.
string pizzaNS::getName()
{
string itsName;
cout << "Please enter your name" << endl;
getline(cin, itsName)
return itsName;
}
The program that this is part of can be run over and over by selecting Y
after each calculation it performs. The program is fine when this function
is commented out. However when this is part of the program it works first
time, but on subsequent tries the program does not pause to allow the user
to input a name. For example
Enter your name.
XXXXXX
Enter the number of pizzas you require
XXXXX
The Second time you can't enter your name.
Enter your Name.
Enter the number of pizzas you require.
XXXXXX
It doesn't pause for input. Can the string still have the previous value in
it despite going out of scope. Is this why it is skipped the second time
around.
The program is an unmanaged program written in VS2003.
Thanking you in advance.
Nifsmith