Preparation knowledge of C + + 3

Source: Internet
Author: User
Tags class definition

1. Assignment statement, assignment statement assigns the value to the storage unit carrots=23. Symbol = is called a copy operation, such as the following code
int Steinway;
int Baldwin;
int Yamaha;
yamaha=baldwin=steinway=77;
Assignment will proceed from right to left, first 77 is assigned to Steinway, then Steinway value is assigned to Baldwin, then Baldwin's
Values are assigned to Yamaha (it is not surprising that the above variables can be arbitrarily changed such as A,b,c)


2.cout of the tricks of course; If you want to print the string "2" and the integer 2. can use the C language Multifunction output function printf ()
printf ("Printing a string:%s", "2");
printf ("Printing an integer:%d\n", 2);
printf () must use special codes (%s and%d) to indicate whether to print a string or a certificate. If you let printf () print
String, but incorrectly provides an integer, because printf () is not sophisticated enough to find the error at all. He will continue to
Processing, showing a pair of garbled characters.
Perhaps you have been accustomed to using printf (), may feel cout a bit strange, some people still insist on using printf () but with
Compared to printf () with all conversion instructions, the advantages of the cout are more pronounced, and it recognizes that the type function shows that the design is flexible
Good. In addition, he says it can be extended. That is, you can redefine the << operator, which is what cout can identify and realistically develop.
The row data type.


3. Use the CIN example:
#include <iostream>
int main ()
{
using namespace Std;
int carrots;
cout<< "How many carrots does you have?" <<endl;
cin>>carrots;
cout<< "Here is both more.";
carrots=carrots+2;
cout<< "Now you have" <<carrots<< "carrots." <<endl;
return 0;
}
This program contains two new features: using CIN to read keyboard input and combine four output statements into one.
Like Cout, CIN is also an object only, and he can convert a series of characters entered by the keyboard to accept
The variable of the information can be accepted in the form. In this example, the program will carrots life as an integer variable
, so the input is converted to the digital form that the computer uses to store the certificate.


4. Splicing with cout; another new feature in Getinfo.cpp is the merging of 4 output statements into one.
The iostream file defines the << operator, and the output can be combined as follows;
cout<< "Now Habe" <<carrots<< "carrots." <<endl;
This allows you to combine the string output and the integer output into a single statement. Similar to the following code.
cout<< "now has";
cout<<carrots;
cout<< "carrots." ;
cout<<endl;
The results of the output are similar.


5. Class; A data type similar to user-defined. To define a class, you need to describe what information he can represent and
What operations the data performs. Class to object is like type to variable. Which means that the class definition describes a data grid
And its usage, while the object is the entity that the operation, specification creates. Class describes all of a data type
Properties, objects are entities created from these descriptions.

Preparation knowledge of C + + 3

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.