+ 2

How to take values in c++

18th May 2018, 10:18 AM
Rahul Sinha [ Left ]
Rahul Sinha [ Left ] - avatar
7 Antworten
+ 3
You can use cin from the <iostream> library. #include <iostream> #include <string> using namespace std; int main() { string x; cin >> x; } It works for all standard data types (int, float, double, string, char,...). However, if you want to read a string, cin will stop reading when it reaches a whitespace: Entering "a b" in the program above will result in x = "a". If you want to read an entire line with whitespaces into a variable, replace the last line with this: getline(cin, x); I think those are the most popular ways for reading values from user input.
18th May 2018, 11:00 AM
Chris
Chris - avatar
+ 2
for example, int a; cout<<"Please enter a number"<<endl; cin>>a;
18th May 2018, 10:52 AM
Ali B.
Ali B. - avatar
+ 2
use 'cin': #include <iostream> using namespace std; int main(){ int number = 0; cout << insert a number; cin >> number; cout << you inserted << number << endl; return 0; }
18th May 2018, 10:54 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
Rahul sinha I did not understand your question.
18th May 2018, 10:30 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
we use scanf in c language then in c++ what is used
18th May 2018, 10:45 AM
Rahul Sinha [ Left ]
Rahul Sinha [ Left ] - avatar
+ 1
we use cin for getting values
22nd Mar 2019, 4:05 PM
Kalpana Reddy
Kalpana Reddy - avatar
0
cin>>
18th May 2018, 12:45 PM
Khushal Patel
Khushal Patel - avatar