Isso é um bug com getline (), ou estou fazendo algo errado. Maneira certa de usar o getline ()?
Pode não ser um bug, mas não sei o que está errado. Minha primeira entrada é repetida para str1 na segunda iteração, e é a mesma maneira a partir de então. Apenas a primeira iteração é boa.
#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;
}
A saída é:
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