The first chapter C + + Programming basics (How to write C + + program) __linux

Source: Internet
Author: User

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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.