P1.1 P6
Read the user's name and store it, and finally greet the user.
#include <iostream>//1
#include <string>//2
using namespace Std; 3
int main ()
{
String user_name;
cout<< "Please enter your name:";
Cin>> user_name;
cout<< ' \ n '
cout<< "Hello,"
<< user_name
<< "Welcome,and Bye bye ...";
return o;
}
The 1.c++ standard "input and Output library", named Iostream, contains the relevant set of classes to support the input and output of terminals and files.
2.string class is used to store data.
3.using namespace Std
4. The number of characters constants is divided into two categories: a type of printable character, such as (English, digital, punctuation), and the other is not printable characters, such as (newline characters \ n tabs \ t ...) The constants quantity is enclosed by a set of single quotes.
See Code for 5.cin,cout usage.
Exercise 1.4 expands on the above question, requires the first and last name of the user, and prints the user's last name and first name.
#include <iostream>
#include <string>
using namespace Std;
int main ()
{
String User_first name,user_last name;
cout<< "Hello,please Enter your name";
Cin>>user_first name;
cout<< "Hello,please Enter your last name";
Cin>>user_last name;
cout<< "Hello\n '
<<user_first Name
<< '
<<user_last name;
return 0;
}