Algorithm competition from c to c ++ 3

const

Constant pointer, pointing to a fixed position, you can not modify the pointed position again, you need to initialize, const is added after the "*" sign, in front of the name, such as int * const p;

A pointer to a constant cannot modify the content at the address, which is equivalent to a constant reference, and const is added before the type;

We turn an object into a constant and cannot call a general member function, because it may change its data, so the system does not allow the general member function to be called, we can only overload the function plus a const member function, written as: return type Name (parameter) const {}

The difference between class and struct:

Class members are private by default, and structs are shared by default.

During initialization, we can call the constructor, we can also use braces to assign values, which is equivalent to copying the constructor, creating objects or how to initialize objects;

 

string class:

There are many similarities with character arrays, we can use subscript access,

Added to the function, overloaded the operation negative, get the length through size (); compare the size of the two character arrays in the character array using strcmp, we can call the class function str1.compare (string) The return value is the same as strcmp

string five (character array, length (default is the length of the preceding character array));

string five(&:pos:n)

Input of string class:

  1. Direct stream input, you can automatically ignore spaces and line breaks.

  2.cin.getline (info, 100), read a line ignoring line breaks.

  3.getline (cin, stuff, interrupted mark) // Read a line, ignoring line breaks.

Operator overloading: six operators

find find a character or a sub-channel, can not find return string :: npos;

Implement string.find ("target", startpos (0)); return subscript;

rfind (, startpos) Find from the right; the last time it appears

find_first_of (); returns the first position that matches any one of the parameters from left to right

find_first_not_of is not in the position of the parameter from left to right;

find_last_of (); same reason;

find_last_not_of is the same;

str.c_str (); returns a const char array to receive with a pointer

string a = s.substr (pos, len); returns a character constant;

 

assert (add a judgment); // Assert that if it fails it will interrupt the program;

 

Guess you like

Origin www.cnblogs.com/hjw201983290498/p/12727909.html