C + + Basics Tutorial-Input statements

Source: Internet
Author: User

Third, the input statement

We've learned the output statement cout, which we'll learn about the input statement cin (read as c-in), let's take a look at an exercise;

1, start Geany

1 point Menu "application-programming-geany" Start Geany, create a new C + + source program;

2 Point Menu "file-Save as" command, to "Shuru" as the filename, save the file to its own folder;

2, input program code

1 in the Blue Code area below, enter the following statement:

int a = 0;

cout << "input A:";

Cin >> A;

cout << "A=" << A;

2 The first line defines an integer variable A and assigns a value of 0.

The second line shows a hint, the third line executes the input statement (read as c-in), and line fourth shows the contents of the variable a at this time;

3 save, compile, build, run, first come out a line of hints, a flash of the cursor, request a number of input;

4 then press the keyboard, enter 20 and then click the Enter key, which shows that the value of the variable A is already 20;

5 The CIN statement can also enter multiple numbers, such as: Cin >> a >> B, when running, separate two input numbers with a space;

Try to practice yourself and enter two numbers at a time.

#include <iostream>

using namespace Std;

int main (int argc, char** argv)

{

int a = 0;

cout << "input A:";

Cin >> A;

cout << "A=" << 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.