- string assign function can be used to assign
- The string into a character array
1: basic_string &assign( const basic_string &str );2: // assign a string with str3: basic_string &assign( const char *str );4: // assignment with an array of characters5: basic_string &assign( const char *str, size_type num );6: // start with str num characters of a string assignment,7: basic_string &assign( const basic_string &str, size_type index, size_type len );8: // sub-string with a string str assigned to index substring starting at the index for len9: basic_string &assign( size_type num, char ch );10: // num characters with a string assignment ch11:
String S; char CH [ 100 ]; strcpy (CH, " Hello, World " ); s.assign (CH); // converts the character string into an array of COUT << endl << S;
String S; char CH [ 100 ]; S = " Hello, World " ; / * strcpy (CH, s.c_str ()); // The first method COUT << CH; * / strncpy (CH, s.c_str (), s.length () + . 1 ); // length s.length () + 1, because terminator cout << ch;
char * strncpy ( char * to, const char * from , size_t count); // string from the copy up to count characters in a string to. If less than the length of the string from the count, the rest with '\ 0' padding. Returns a string processing is completed. const char * the c_str (); // the c_str () function returns a pointer pointing to regular C string, this string with the same content.