+ 2
How to take values in c++
7 Answers
+ 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.
+ 2
for example,
int a;
cout<<"Please enter a number"<<endl;
cin>>a;
+ 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;
}
+ 1
Rahul sinha I did not understand your question.
+ 1
we use scanf in c language then in c++ what is used
+ 1
we use cin for getting values
0
cin>>