Translations of this page?:

String constructors

Syntax:

    #include <string>
    string();
    string( const string& s );
    string( size_type length, const char& ch );
    string( const char* str );
    string( const char* str, size_type length );
    string( const string& str, size_type index, size_type length );
    string( input_iterator start, input_iterator end );
    ~string();

The string constructors create a new string containing:
string 构造函数创建包含以下内容的新 string 对象:

  • nothing; an empty string,
    什么都没,一个空的 string 对象
  • a copy of the given string s,
    已知 string 对象 s 的一份副本
  • length copies of ch,
    字符 ch 的 length 份副本
  • a duplicate of str (optionally up to length characters long),
  • a substring of str starting at index and length characters long
    str 对象的一个子对象,从 index 索引值后 length 长度的字符集
  • a string of characters denoted by the start and end iterators
    由 start 和 end 迭代器指定的字符集的一个 string 对象

例如:

     string str1( 5, 'c' );
     string str2( "Now is the time..." );
     string str3( str2, 11, 4 );
     cout << str1 << endl;
     cout << str2 << endl;
     cout << str3 << endl;

显示:

     ccccc
     Now is the time...
     time

The string constructors usually run in linear time, except the empty constructor, which runs in constant time.
string 类的构造函数的运行时长通常是线性的,除了空构造函数,它的运行时长是固定的。

 
• • • SitemapRecent changesRSScc