0
Why getline() is not working in SoloLearn?
Whats going on? https://code.sololearn.com/cbTMYeHWl9uV/?ref=app
4 Answers
+ 7
getline() is used to input strings.
So u need to declare str as string , like"string str; "
https://code.sololearn.com/cJF3N6pVcx0H/?ref=app
+ 6
As pointed out by BEGGINER ,You are voilating the syntax of getline() which is :-
istream& getline(istream& , string&, char opitional_delimiter);
The second argument that you are providing is not of type *string* instead is of type char[] { array of characters or c- style string } which is resulting in error
here is the fixđ
https://code.sololearn.com/chwKSZh3n3YG/?ref=app
+ 6
Yes.
For charecter array input use
cin.getline(str,20); //20 max length of array
+ 1
Okay, if I am using getline() to input c-style string, then
cin.getline(str_name,ending_size)
This the way to go.
However, C++ have string class through which we can input string, (i was unaware of that).
Again
String str;
cin>>str;
If I gave input "Solo Learn"
Then output becomes : Solo
If i have to get with blank space also then
getline(cin,str);
This will solve that issue.
Thanks everyone !!
https://code.sololearn.com/cbTMYeHWl9uV/?ref=app