+ 1

How use space in string C++ ?

C++ String

6th Sep 2017, 7:27 AM
Irman Utamara
Irman Utamara - avatar
4 Antworten
+ 2
You can use spaces normal when you create string for example string a = "hello world". If you want to get this string as input you can use std::getline(cin, string) function. It gets all line of input.
6th Sep 2017, 7:54 AM
SKELU21
SKELU21 - avatar
+ 1
if i use array on string, getline(cin,string[i]) can not work @SKELU21 @Baptiste E. Prunier
6th Sep 2017, 12:20 PM
Irman Utamara
Irman Utamara - avatar
0
If you meant in input using cin, then use : string s; getline(cin,s);
6th Sep 2017, 10:44 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
It seems normal as string is a class, not a variable string s[5]; for(int i = 0; i < s.size(); ++i) getline(cin, s[i]); Should work
6th Sep 2017, 2:26 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar