I am having problems with the getline() function. While reading through tutorials to solve it, I copied an example code and compiled it and it gave me the same error:
The code is:
The ouput and my inputs are:
I think it is clear enough to show the problem. Why is the program is behaving like this? Thank you for your time.
The code is:
Code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string mystr;
cout << "What's your name? ";
getline (cin, mystr);
cout << "Hello " << mystr << ".\n";
cout << "What is your favorite team? ";
getline (cin, mystr);
cout << "I like " << mystr << " too!\n";
return 0;
}
Code:
What's your name? JUAN [I]<enter>[/I] SOULI [I]<enter>[/I] Hello Juan. [I]<enter>[/I] What is your favorite team? THE ISOTOPES [I]<enter>[/I] I like SOULI too!
Comment