String constructors

来自cppreference.com
跳转到: 导航, 搜索

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 類的構造函數的運行時長通常是 線性的,除了空構造函數,它的運行時長是 固定的。

个人工具
名字空间
操作
导航
工具箱
其他语言