- 1

How can print all my text even when I input a text with space within.

In my code, I realised if I input a two or more words with spaces in between, the compiler ignores the postceeding ones and only outputs the first word. https://code.sololearn.com/cHvVb65Tqv6Z/?ref=app

12th Jul 2021, 5:41 PM
Frimpong Godfred
Frimpong Godfred - avatar
5 Answers
0
You have to use getline()
12th Jul 2021, 5:43 PM
InFany
InFany - avatar
0
As in cin << getline(var) Or
12th Jul 2021, 5:46 PM
Frimpong Godfred
Frimpong Godfred - avatar
0
No, getline is function, you must pass parameters to it. cin.getline(string, streamsize, separator); For example #include <iostream> using namespace std; int main() { char str[256]; cout << "Enter four sentence: " << endl; cin.getline(str, 256, ';')); cout << str; cin.getline(str, 256, ';')); cout << str; }
12th Jul 2021, 5:54 PM
InFany
InFany - avatar
- 1
Return the code and replace + with << But if you want to use "getline" use std::getline(cin, f);
12th Jul 2021, 6:13 PM
Solo
Solo - avatar