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
#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
// i/o example
#include <iostream>
using namespace std;
int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
return 0;
}
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
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
// i/o example
#include <iostream>
using namespace std;
int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << ".\n";
return 0;
}
// output
/* Please enter an integer value: 702
The value you entered is 702 and its double is 1404. */
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