Hello everyone,
I just started reading the <jumping into c++>, it's a fantastic book.
I got a question about sample Code 9: string_append.cpp
I made 2 changes with the sample, then the program stopped working properly.
I better show you:
Code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string user_first_name;
string user_last_name;
string user_full_name = user_first_name + " " + user_last_name;
cout << "Please enter your first name: ";
cin >> user_first_name;
cout << "Please enter your last name: ";
//cin >> user_last_name;
getline(cin, user_last_name, '\n');
//string user_full_name = user_first_name + " " + user_last_name;
cout << "Your name is: " << user_full_name << "\n";
cin.get();
cin.ignore();
}
As you can see, the two "//" commented out lines were originally in the sample, but I put string user full name on top, and used getline instead of cin. Then this happened:
If I only change the position of string user full name, without changing cin to getline, this is what happened: no display
I'm using visual studio 2010, and I have no idea why this is happening, please help
thanks a lot guys