mardi 12 janvier 2021

Why does using two getline function together, second one doesn't take the /n character?

#include <bits/stdc++.h>
using namespace std;
int main(){
string str1, str2;
getline(cin, str1);  // aaa
getline(cin, str2);  // bbb
cout << str1 << " " << str2;   // aaa bbb
return 0;
}

Why 2nd getline doesn't take /n, when I input str1 as "aaa\n"?

Aucun commentaire:

Enregistrer un commentaire