A comprehensive analysis of the C ++ Language

Source: Internet
Author: User

The C ++ language has improved the C language in two ways: Object-oriented and template technology, the following describes the features of the C ++ language.

But I believe this function will be added in the future.) The template is a complicated part of C ++, but as a real C ++ programmer, this part is very important. It is particularly important to master the C ++ standard library. At the beginning, do not directly rush to various guides and designers in VC.

Because a lot of code generated by relying on the development environment will confuse us, it is not conducive to learning the C ++ language itself. My suggestion is to generate an empty console project and add files to it by yourself. The following is a simple console program:

 
 
  1. //robindy/list.cpp  
  2.  
  3. #include <iostream> 
  4. #include <list> 
  5.  
  6. using namespace std;  
  7.  
  8. int main()  
  9. {  
  10. list<char> coll;  
  11.  
  12. for(char c = \'a\'; c <= \'z\'; ++c)  
  13. {  
  14. coll.push_back(c);  
  15. }  
  16.  
  17. list::const_iterator pos;  
  18. for(pos = coll.begin(); pos != coll.end(); ++pos)  
  19. {  
  20. cout << *pos << \' \';  
  21. }  
  22. cout << endl;  
  23.  
  24. return 0;  

Description of using namespace std;: namespace refers to various visible ranges of identifiers. All identifiers in the C ++ standard library are defined in a namespace named std.

Due to the concept of namespace, when using any identifier of the C ++ standard library, You can have three options: 1. Specify the identifier directly. For example, std: ostream instead of ostream. The complete statement is as follows: std: cout <std: hex <3.4 <std: endl; 2. Use the using keyword.

Using std: cout; using std: endl; The above program can be written as cout <std: hex <3.4 <endl; 3. the most convenient way is to use using namespace std; in this way, all identifiers defined in the namespace std are effectively exposed ). They are declared as global variables. The preceding statement can be written as follows: cout

This program uses the standard template library to print characters a ~ on the screen ~ Z. Only two types of main functions are accepted by the C ++ Standards Committee. Only the following two methods are compatible with the C ++ standard and can be transplanted. That is:

 
 
  1. Int main ()
  2. {
  3. }
  4. And
  5. Int main (int argc, char * argv [])
  6. {
  7. }

C ++ defines an implicit return 0 at the end of main), but the return statement must be explicitly written in VC. You can compile BCB without writing return. This program uses the STL container: linked list. Insert 26 letters into the linked list, and then output characters from the matrix. I do not recommend that you start with the template library from the very beginning.

However, I suggest you gradually learn the template library consciously. For example, we should be familiar with cout and cin usage in iostream), and reduce the use of printf and SC anf in older C function libraries. The advantage of starting from the console is to avoid understanding other code generated by tools such as the wizard in VC.

  • Introduction to C ++
  • Describes how to optimize C ++ compiler variables.
  • C ++ Data Types
  • Rich C/C ++ Programming
  • Introduction to C ++ hosting technology

The entire process is clear. A major difficulty for beginners to learn about VC is that they cannot figure out the entire program process starting from the statement and then exit from the statement. MFC has made too many encapsulation to cover up the truth ....

Through the console, we can quickly learn many new features in the C ++ language. Such as class encapsulation, inheritance, and polymorphism. Through this period of study, we must be able to master three things: C ++ keywords, the focus of the syntax is on object-oriented, and templates), C ++ standard library know how to use it, it takes a lot of time and effort to thoroughly master ).

A large part of the interface-related interfaces (MFC) are interface-related classes, so I think it is very bloated and boring! Looking back at the previously written programs using MFC, there is a kind of "junk" feeling .) Test it by yourself: Write a console program, in which class inheritance, function overload, dynamic polymorphism is implemented through virtual functions), Data encapsulation, and use of c ++ standard library.

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.