C++primer Chapter III

Source: Internet
Author: User

//1. Code that is located in a header file should not generally use a using declaration. This is because the contents of the header file are copied to all the files that reference it, which can result in unexpected namespace collisions. //three ways to use names in namespaces    using namespaceStd//It is best not to use in the header file, it is easy to cause namespace name pollution, resulting in naming conflicts    usingSTD::string; STD::string;//2. A set of functions for manipulating characters is defined in the header file Cctype//isalnum (), Isalpha (), Iscntrl (), IsDigit (), Isgraph (), Isprint (), ispunct (), Isspace (), Isupper (), Isxdigit (), Tolow ER (), toupper ()//3. For operator &&, only the left evaluates to true to continue evaluating the right side//4. When it is unclear what type of container to use, use an iterator to manipulate the elements of the container and use the actions common to the iterator (*it, It->men, ++it,--it, it1 = = It2, it1! = it2), which is convenient when replacing the container. vector<int> Vecint (Ten);//10 0 is stored in the Vecint, the value is initialized at this timevector<int>::iterator Itvec =Vecint.begin ();//5. The number of elements in an array is also part of the array type, and the compile-time dimension should be known, so its dimension must be a constant expression.     Charbuff[Ten] ="SZN";//allows the use of a string constant to initialize the character array buff is readable and writable    Char*str ="SZN";//It's best not to use it    /*string Constants in C++03 const CHAR[N] When there is an obvious target type, the result of a conversion as a qualifying modification is char*, which is an obsolete clause that has been discarded in c++11, that is, in c++03, Char *tem= "    Szn "; Is legal but illegal in c++11, c++11 must write this: const char * tem =" SZN "; In C, a sequence of characters enclosed in double quotation marks is not called a string constant, it is just a string literal, and C's string literal is not a constant, because C's constants and constant expressions are only compile-time.    string literals in C + + can be called string constants.    The string literal type in C is char[n], the array-to-pointer conversion result is char*, and the string constant type in C + + is const CHAR[N], and the result of the array-to-pointer conversion is the const char*. *///6. An attribute of an array: In many places where the array name is used, the compiler automatically replaces it with a pointer to the first element of the array, and the pointer loses the attributes of all the arrays. //The new 7.C++11 Standard introduces two functions called Begin (), End (), and is similar to the container's function of the same name. Can be used for built-in arrays. defined in the header file iterator. //8. The value in the subscript operator for the built-in type can be negative, but the standard library type qualifies the subscript that it uses to be an unsigned type. 

C++primer Chapter III

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.