+ 1

User Input Help (Solved)

anytime I put user input coding, it only prints numbers and not statements. example: #include <iostream> using namespace std; int main() { int firstName; cin >> firstName; cout << " Enter Your First Name:" << endl; cout << firstName << " " << endl; return 0; } Any help ? thank you in advance.

1st Feb 2017, 2:43 PM
Samuel
Samuel - avatar
3 ответов
+ 4
replace int firstName; by string firstName; and add the header #include <string> after iostream int is the data type for integers = natural numbers.
1st Feb 2017, 2:51 PM
Mario L.
Mario L. - avatar
0
Thank You !
1st Feb 2017, 2:52 PM
Samuel
Samuel - avatar
0
using string #include<iostream.h> #include<string.h> int main(){ string s; cour<<"Enter Firstname"; cin>>f_name; cout<<"Your Firstname is "<<f_name; return 0; } using character array #include <iostream.h> int main(){ char f_name[20]; cout<<"Enter Firstname:"; cin>>f_name; cout<<"Your Firstname is "<<f_name; return 0; }
1st Feb 2017, 3:05 PM
Avnish Tomar (CCS University)
Avnish Tomar (CCS University) - avatar