C + + Primer Plus (chapter4-1)

Source: Internet
Author: User

The first half is simple and records only the uniqueness. While the pointer is important, another one is opened.

The C-style string ends with a null character.

Strlen (char []); (CString and String.h) calculate the number of visible characters without null characters

About functions generally only record their prototypes, sometimes in order to not conform to the syntax, the comment () is its header file

CIN uses whitespace to determine the end of a string when processing a string, and ignores whitespace when read, but leaves it in the queue so that only one word can be read.

Cin Cin.getline (char [],int)//reads one line at a time, ends with a newline character, and discards on read, reads the first parameter-1 characters to save to the second parameter.

Cin Cin.get (char [], int) and getline () are the same but do not discard newline characters cin.get () read one character. Cin.get (char [], int). Get () and Cin.getline (char [],int) have the same effect.
Get () will set failbit after reading a blank line, and the next input will be blocked, and the input can be restored with cin.clear (). The input string may be longer than the allocated space, get (), getline () will leave the remaining characters in the queue, and Getline () will also set failbit and close the input.
Mixing with Cin and getline ()/get () often appears to leave enter in the queue, which is considered a blank line, resulting in failbit.

strcpy (Char [], Char [])  //(CString and String.h) copy 2 to 1strcat (char [], Char [])  // (CString and String.h) add 2 to 1 and remove the null character behind 1.

Getline () for string is Getline (cin,string), get () is also

Original string: The character represents itself, and there is no escape character. Use R to identify the original string, "(and)" to be defined by default, but can be in "and (to change the default qualifier, but must be synchronized before and after, not symmetric, and not with whitespace.) Such as

R "+* (" (AAABBBBBBBB) ", aaaaaaaaaa) +*"

Required after the end declaration of struct and Class};
Structs can do the work of defining structures and creating structural variables at the same time.

struct example{    int A;    Char B} c,d;//can even be initialized, struct a{    int b;    char c;} d={2, ' a '}; It can also be initialized with the generic {}. You can also declare struct,struct{int a without a name    ;    char b;} C The structure can no longer be created, but it is possible to initialize and access C;

C + + also allows a struct member to be specified that occupies a specific number of bits, as in C.

struct bitfield{    unsigned int sn:4;//4 bits for SN value    unsigned int:4;//4 bits unused    bool Boolvalue 1;} The field type should be an integer or an enumeration, and fields with no names are used to provide spacing, and each member is called a bit field. For example, members of Bitfield should say two and one spacing, such as its initialization bitfield example = {278,true};

Union can store different data, but only one of the data

Union One4all{int Int_val;long long_val;double Double_val;}; int main () {One4all value;value.int_val=15;cout<<value.int_val<<endl;value.double_val=18.3;cout< <value.double_val<<endl;cout<<value.int_val; Error  When I test output is-858993459}

The reason for the error above is easy to see the difference between a struct and a union, where the Union can store only one value at a time, and one of its uses is to save space when a data item uses two or more types, but not both. Of course, the union size is the largest member of its storage.

For enumeration types, only the enumerator used when defining the enumeration can be assigned to this enumeration variable without casting.

enum Spectrum {Red,orange,yellow,green,blue};spectrum band=Blue;
// Valid
Spectrum Band2=2//Invalid, 2 not an Enumerato

An enumeration type is defined only by an assignment operator, and an enumeration can be promoted to an int type, but an int is not automatically converted to an enumeration type, casting an inappropriate value, and the result is undefined.

int value=1+red; Validspectrum Band=red+orange; Invalidspectrum Color=spectrum (5); Undefined

C + + Primer Plus (chapter4-1)

Related Article

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.