xxxxxxxxxx
int x;
cout << "hurry, give me a number!: "; // Type a number and press enter
cin >> x; // Get user input from the keyboard
cout << "you picked: " << x << " !" // Display the input value
OR use:
getline >> (cin, variable-name);
instead of
cin >> x;
xxxxxxxxxx
#include <iostream>
int main(){
std::string firstname; //variable created as a string
std::cout << "What's your first name\n";
std::cin >> firstname;//asking for the users' first name
std:: cout << "Hello " << firstname
}
//Works for anyone, don't need any packages, just type this is in and run it.
xxxxxxxxxx
/*Q: Write a program that ask the user to enter the roll
number, section, CGPA and print the formatted output
on the screen?*/
#include<iostream>
using namespace std;
int main()
{
int a;
char b;
float c;
cout<<"Roll Number:"<<a;
cin>>a;
cout<<"Section\t :"<<b;
cin>>b;
cout<<"CGPA\t :"<<c;
cin>>c;
return 0;
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
string first_name, last_name;
int age;
//prompt the user to enter there first name and store the value
cout << "Enter your first name: ";
getline(cin, first_name);
//request the user to enter there last name and store the value
cout << "Enter your last name: ";
getline(cin, last_name);
//request the user to enter there age and store the value
cout << "Enter your age: ";
cin >> age;
//print an output string to the terminal
cout << "Your full name is " << first_name << " " << last_name << " and you are " << age << " years old." << endl;
}
xxxxxxxxxx
int main(){
std::string firstname; //variable created as a string
std::cout << "What's your first name\n";
std::cin >> firstname;//asking for the users' first name
std:: cout << "Hello " << firstname
xxxxxxxxxx
int x;
cout << "Type a number: "; // Type a number and press enter
cin >> x; // Get user input from the keyboard
cout << "Your number is: " << x; // Display the input value
xxxxxxxxxx
string_t question = "What is your name? >> ";
string_t name;
std::cout << question;
std::getline(std::cin >> std::ws, name); // multi words input
std::cin >> name; // only first word
std::cout << "Hello " << name;