C ++ basic knowledge

Source: Internet
Author: User
C ++ basic knowledge 1. Although C ++ is mainly a new language developed based on C, it is not a substitute for C, not an upgrade of C, and C ++ and C are brothers. No one is more advanced than anyone else. More importantly, the standards committees of C and C ++ are independent, and the latest standards of C ++ are c ++ 98, the latest C standard is c99. Therefore, I didn't talk about C ++ first, nor (note that this "no") about C ++, which is a superset of C syntax.
2. c ++/CLI and C # are Microsoft's, and they have nothing to do with C and C ++, although some syntaxes are similar. But which two languages are not similar? The 26 letters ABC.
3. do not use ancient compilers such as TC/TC ++/BC/CB to learn C/C ++, because they are too old to support new C/C ++ standards. Do not make cbx/VC ++ 6.0/vc2005 and other compilers that do not support the C/C ++ standard well. Although these compilers are suitable for work, they are not suitable for learning, because they have many syntax traps. Remember that the only compiler suitable for learning is gcc/mingw.
4. Do not use "" Instead <> to include system header files. Although some compilers allow you to do so, it does not comply with the C/C ++ standard. Example of an error # include "stdio. H", # include "iostream"
5. Do not define the return type of the main function as void. Although some compilers allow you to do so, it does not comply with the C/C ++ standard. Do not omit or write the int return type of the function. In C ++, the compiler must give at least one warning. Example of an error: void main () {}, main (){}
6. Do not paste # include "stdafx. H" in VC ++. It is a pre-compiled header file. It is like not putting the cook in the tray when serving the food.
7. [c ++] Do not # include <iostream. h>, do not # include <string. h> because they have been explicitly removed from the C ++ standard, change them to # include <iostream> and # include <cstring>.
The rule is:
A. If the header file is unique to the old c ++ file, remove the. h extension and put it in the STD namespace. For example, change iostream. h to iostream.
B. If this header file is also available in C, remove the. h suffix and add a C prefix. For example, change string. h to cstring or stdio. h to cstdio.
BTW: Do not confuse <string. h>, <cstring>, and <string>.
BTW: Windows. H is not a standard file of C/C ++, so it is named C/C ++.
8. instead of writing a char * P = "XXX" statement, you must write it as const char * P = "XXX". The reason why the compiler compiled the former is to be compatible with a large amount of old code.
BTW: const type * P is the same as type const * P, and the style is different.
BTW: the const keyword is also found in C.
9. do not include multiple ++/-- variables in the same statement, because their Parsing is not specified in the C/C ++ standard and depends entirely on the individual behavior of the compiler.
10. C/C ++ is a platform-independent language. Therefore, process/GUI related to the system is not in the Standard C/C ++ library. For example, graphics. h and windows. h are provided by a compiler rather than C/C ++.
11. C/C ++ is only a language and platform-independent language.
Some people on the forum even think that C is dos and C ++ is windows. What is Linux?
12. [c ++] object-oriented language was once the main purpose of designing C with class (the predecessor of C ++), but C ++ is not. c ++ is a multi-model language. It mainly supports four programming models: Process calling, Object-based, object-oriented, and generic programming. Of course, it also supports functional, generative, Meta programming and other models.
13. Syntax writers are not writers. Therefore, when you learn a computer language, you also need to learn Data institutions and algorithms, and master the usage of tools and platform APIs.
14. C/C ++ is a common language, so the syntax is very complicated. You should cut it into a set of suitable syntaxes, such as better C and ADT.
15. c/C ++ is a common language. Therefore, it only contains a common library. You should enrich the library you need, for example, the automobile industry association has its own C/C ++ function/class/template library.
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /////////Overview of C/C ++ header files # include <assert. h> // set the insertion point
# Include <ctype. h> // Character Processing
# Include <errno. h> // defines error codes.
# Include <float. h> // floating point number processing
# Include <fstream. h> // file input/output
# Include <iomanip. h> // parameterized input/output
# Include <iostream. h> // Data Stream Input/Output
# Include <limits. h> // defines the maximum constants of various data types.
# Include <locale. h> // defines the localization function
# Include <math. h> // defines mathematical functions.
# Include <stdio. h> // define Input/Output Functions
# Include <stdlib. h> // defines miscellaneous functions and memory allocation functions.
# Include <string. h> // string processing
# Include <strstrea. h> // array-based input/output
# Include <time. h> // defines the time function.
# Include <wchar. h> // wide character processing and input/output
# Include <wctype. h> // wide character Classification
//////////////////////////////////////// //////////////////////////////////
Standard C ++ (same as above)
# Include <algorithm> // General STL Algorithm
# Include <bitset> // STL bit set container
# Include <cctype>
# Include <cerrno>
# Include <clocale>
# Include <cmath>
# Include <complex> // plural class
# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <ctime>
# Include <deque> // STL double-end queue container
# Include <exception> // exception handling class
# Include <fstream>
# Include <functional> // STL defines operation functions (instead of operators)
# Include <limits>
# Include <list> // STL linear list container
# Include <map> // STL ing container
# Include <iomanip>
# Include <IOS> // Basic Input/Output support
# Include <iosfwd> // pre-declaration used by the input/output system
# Include <iostream>
# Include <istream> // basic input stream
# Include <ostream> // Basic output stream
# Include <queue> // STL queue container
# Include <set> // STL collection container
# Include <sstream> // string-based stream
# Include <stack> // STL stack container
# Include <stdexcept> // standard exception class
# Include <streambuf> // underlying input/output support
# Include <string> // string class
# Include <utility> // STL common template class
# Include <vector> // STL dynamic array container
# Include <cwchar>
# Include <cwctype>
Using namespace STD;
//////////////////////////////////////// //////////////////////////////////
C99 added
# Include <complex. h> // plural Processing
# Include <fenv. h> // floating point Environment
# Include <inttypes. h> // integer format conversion
# Include <stdbool. h> // Boolean Environment
# Include <stdint. h> // integer environment
# Include <tgmath. h> // general mathematical macros

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.