Czy jest to błąd związany z getline (), czy też robię coś złego. Właściwy sposób korzystania z getline ()?
To może nie być błąd, ale nie wiem, co się dzieje. Mój pierwszy wpis jest powtarzany dla str1 na drugiej iteracji i od tego samego czasu. Tylko pierwsza iteracja idzie dobrze.
#include <iostream>
#include <string>
using namespace std;
int main () {
cout << " \n Enter two words. \n " ;
char c = 'y';
string str;
string str1;
while (c == 'y'){
getline(cin,str);
getline (cin,str1);
cout << " \n\n str : " << str << " str1 : " << str1 ;
cout << " \n Continue ? \n " ;
cin >> c;
}
return 0;
}
Dane wyjściowe to:
Enter two words. hello world this is mr str : hello world str1 : this is mr Continue ? y hello world str : str1 : hello world Continue ? n