Conversion string array of class and character

  1. string assign function can be used to assign
    1.   1:  basic_string &assign( const basic_string &str );
        2: // assign a string with str
        3:   basic_string &assign( const char *str );
        4: // assignment with an array of characters 
        5:   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 len 
        9:   basic_string &assign( size_type num, char ch );
       10: // num characters with a string assignment ch
       11: 
      String S;
       char CH [ 100 ]; 
      strcpy (CH, " Hello, World " ); 
      s.assign (CH); // converts the character string into an array of 
      COUT << endl << S;
  2. The string into a character array
    1. 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.

Guess you like

Origin www.cnblogs.com/cyj1258/p/12183081.html