0

Why getline() is not working in SoloLearn?

Whats going on? https://code.sololearn.com/cbTMYeHWl9uV/?ref=app

27th Nov 2020, 2:48 PM
Bibek Pant
Bibek Pant - avatar
5 Antworten
+ 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
27th Nov 2020, 3:00 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 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
27th Nov 2020, 2:59 PM
Arsenic
Arsenic - avatar
+ 6
Yes. For charecter array input use cin.getline(str,20); //20 max length of array
27th Nov 2020, 3:00 PM
Jayakrishna 🇮🇳
+ 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
28th Nov 2020, 1:32 AM
Bibek Pant
Bibek Pant - avatar