Mix standard library class string and C-style strings
You can initialize a string class object with the literal character of strings. Typically, because C-style strings have the same data type as string literals, and are null-character-free, you can use a C-style string in any place where you can use string literals.
1. You can initialize or assign a string using the C-style string.
The addition operation of the 2.string type requires two operands, and a C-style string can be used as one of the operands, as well as a C-style string as the right-hand operand of a compound assignment operation.
Conversely, it is not valid to use the standard library string object directly where the C-style string is required. If you cannot initialize a character pointer with a string object.
char *str = ST2; Error
const char *STR = ST2.C_STR (); correctly, the C_STR function returns a C-style string that returns a pointer to the first address of the character array that holds the same content as the string object and ends with null.
C_str The returned pointer points to an array of const char types.
The array returned by C_STR is not guaranteed to be valid, and subsequent operations on ST2 may alter the value of ST2 to invalidate the array just returned. If your program needs to continuously access the data, you should copy the array returned by the C-STR function.
You cannot initialize another array directly with an array, the programmer can only create a new array, and then explicitly copy the elements of the source array to the new array individually. C + + allows you to initialize a vector object with an array, you must indicate the first element used for initialization and the address of the next location of the array with the most element.
Vector<int> Ivec (Int_arr, Int_arr + arr_size); The two pointers passed to ivec the range of vector initial values, and the second pointer points to the address space after the last element being copied.
Initialization creates a Ivec that contains arr_size elements