C ++ basic tutorial-input statements

Source: Internet
Author: User

Iii. Input statements

We have learned the output statement cout. in this section, we will learn the input statement cin (read as c-in). Let's take a look at this exercise;

1. Start Geany

1) Click "Application-programming-Geany" in the menu to start Geany and create a c ++ source program;

2) Click the "file-save as" command to save the file to your folder with "shuru" as the file name;

2. Enter the program code.

1) in the following blue code area, enter the following statement:

Int a = 0;

Cout <"input :";

Cin>;

Cout <"a =" <;

2) The first line defines an integer variable a with a value of 0,

The second line displays a prompt. The third line executes the input statement (read as c-in), and the fourth line displays the content in variable;

3) after saving, compiling, generating, and running, a prompt is displayed first. The cursor is flashing and a number is required;

4) press the keyboard, enter 20, and then press the Enter key to display that the value of variable a is 20;

5) You can also enter multiple numbers in the cin statement, for example, cin> a> B. separate the two numbers with spaces during running;

Try to exercise and enter two numbers at the same time;

# Include <iostream>

Using namespace std;

Int main (int argc, char ** argv)

{

Int a = 0;

Cout <"input :";

Cin>;

Cout <"a =" <;

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.