Why is it that whenever I use the getline function I get an error during execution. To clarify...
I have this code;
cout<<"Enter your string: ";
getline(cin, myString); //line 1
cout<<"Enter your name: ";
getline(cin, myName); //line 2
cout<<"Age: ";
cin>>age; //line 3
output:
____________________________
Enter your string: gfgfkjhjkhgg
Enter your name:
Age: 25
____________________________
As you can see, when you use the getline function the second time, the extraction stream fails and skips to the next non-String variable. Is that not weird? The result is that you can't enter any succeeding string variables anymore.
What is the solution to this?
Thanks in advance.