+ 2

[C++] How to get as input more then one word?

Here is my code: int main() { string sen; cout << "Enter a sentence to be translated into Pig Latin:" << endl; cin >> sen; cout << "You entered:" << sen << endl; return 0; } Whenever i enter as input more then one word, it only prints the first one. How can I get as input a whole sentence, such as "This is a pig latin sentence"?

23rd Apr 2017, 6:41 AM
Nathan
Nathan - avatar
2 Réponses
+ 17
getline(cin, sen); instead of cin >> sen;
23rd Apr 2017, 6:52 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Thanks! it worked!
23rd Apr 2017, 7:05 AM
Nathan
Nathan - avatar