¿Es esto un error con getline (), o estoy haciendo algo mal. ¿La forma correcta de usar getline ()?
Puede que no sea un error, pero no sé qué está mal. Mi primera entrada se repite para str1 en la segunda iteración, y es la misma forma a partir de entonces. Sólo la primera iteración va bien.
#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;
}
La salida es:
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