+ 2
Which command is available in C++ for taking multiple words as an input like gets(is available in C language)???
C++ Beginner
4 Respostas
+ 6
Taking multiple words as part of a longer string could be achieved by using getline() function. Unlike cin stream object which throws away anything after encountering the first space on the inputted sequence, getline() would keep the whole thing including the spaces between each character group (word).
●●usage●●
string userInput = "";
cout << "Your input is ";
cin >> userInput;
Input is : "C++ Programming" and the stored sequence in userInput variable is "C++".
getline(cin, userInput);
Now, with the same input as before, the stored sequence in userInput variable is "C++ Programming"
+ 5
getline command
syntax getline(cin,varname)
string h,
getline(cin,h);
+ 2
Hi Jaydeep Machhi can you give an example of what input were you expecting, and how you expect the output to be? maybe explain in question Description to be more specific. Thanks : )
+ 1
like if I want to take input as a 'Solo learn' now I can easily take it as an input in C language by simply using 'gets' but I can't use 'gets' in C++.