+ 1
How to user input a string variable?
This is my code:- 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 int main() { 6 7 string myString; 8 cout << "Enter String:" <<"\n"; 9 10 return 0; } Now my question is what should i write in line number 9 to take a string input from the user so that I can perform operations on it. Also what should be the command to display the output string.
3 Respostas
+ 11
Just adding to @Manual's answer, if you want to take an entire line of input (including whitespaces, terminated by newline), use getline().
string myString;
cout << "Enter String : ";
getline(cin, myString);
+ 4
Here is an example
https://code.sololearn.com/cBYMzk62djGa/?ref=app
+ 1
@Designex
Put the code in the playground
Use
(Console in)
Cin >>
on the value you want the input to go to.