0

can someone explain how to use char to print out the character with space.. such as a person name... for example John Cena...

i have tried to code in c++ the john cena name... but the cout is only John... can someone help me... i tried the header of cstring.. but i dont know how it worked.. for those who replied i really appreciate it.. (:

14th Oct 2018, 4:16 PM
Abdul Malik
Abdul Malik - avatar
7 ответов
+ 7
cin ignores every thing after space, which means it keeps reading until it encounters any whitespace. So in order to tackle that problem we use getline() function which also handles whitespaces(spaces and tabs).
14th Oct 2018, 7:52 PM
blACk sh4d0w
blACk sh4d0w - avatar
0
cout << "John Cena";
14th Oct 2018, 4:35 PM
TurtleShell
TurtleShell - avatar
0
oh soory..
14th Oct 2018, 5:00 PM
Abdul Malik
Abdul Malik - avatar
0
i mean that.. char name[32] cin>>name; cout<<name
14th Oct 2018, 5:01 PM
Abdul Malik
Abdul Malik - avatar
0
the output is only john
14th Oct 2018, 5:01 PM
Abdul Malik
Abdul Malik - avatar
0
Im not a C++ expert so I looked about and the problem is with cin and the easiest way I found was to use a string and the getline() function... string name; getline(cin, name); cout >> name;
14th Oct 2018, 5:21 PM
TurtleShell
TurtleShell - avatar
0
oh.. thank you All
15th Oct 2018, 12:56 AM
Abdul Malik
Abdul Malik - avatar