Ist das ein Fehler mit getline () oder mache ich etwas falsch? Richtiger Weg, um getline () zu verwenden?

Es ist vielleicht kein Fehler, aber ich weiß nicht, was falsch läuft. Mein erster Eintrag wird bei der zweiten Iteration für str1 wiederholt und ist ab dann genauso. Nur die erste Iteration funktioniert.

#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;
}

Die Ausgabe ist:

 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


Antworten auf die Frage(2)

Ihre Antwort auf die Frage