basic_string::basic_string

空の場合は、特定の文字が、初期化されてのラッパを構築する、または別の文字列またはオブジェクトの C スタイルの null で終わるな (文字列) の全体または一部のコピーは文字列です。

basic_string();
explicit basic_string(
    const allocator_type& _Al
);
basic_string(
    const basic_string& _Right
);
basic_string(
    basic_string&& _Right
);
basic_string(
    const basic_string& _Right, 
    size_type _Roff,
    size_type _Count = npos
);
basic_string(
    const basic_string& _Right, 
    size_type _Roff,
    size_type _Count, 
    const allocator_type& _Al
);
basic_string(
    const value_type *_Ptr, 
    size_type _Count
);
basic_string(
    const value_type *_Ptr, 
    size_type _Count,
    const allocator_type& _Al
);
basic_string(
    const value_type *_Ptr
);
basic_string(
    const value_type *_Ptr,
    const allocator_type& _Al
);
basic_string(
    size_type _Count, 
    value_type _Ch
);
basic_string(
    size_type _Count, 
    value_type _Ch,
    const allocator_type& _Al
);
template <class InputIterator>
    basic_string(
        InputIterator _First, 
        InputIterator _Last
    );
template <class InputIterator>
    basic_string(
        InputIterator _First, 
        InputIterator _Last, 
        const allocator_type& _Al
    );
basic_string(
   const_pointer _First,
   const_pointer _Last
);
basic_string(
   const_iterator _First,
   const_iterator _Last
);

パラメーター

  • _Ptr
    構築 string を初期化するために使用される文字が C 文字列。 この値は、null ポインターにすることはできません。

  • _Al
    構築された String オブジェクトの領域のアロケーター クラス。

  • _Count
    初期化される文字数。

  • _Right
    構築された文字列を初期化する文字列。

  • _Roff
    構築された文字列の文字値を初期化するために使用される 1 番目の文字列の文字のインデックス。

  • _Ch
    構築された文字列にコピーする文字値。

  • _First
    挿入されるソース範囲内の先頭の要素を指定する入力反復子、const_pointer、または const_iterator。

  • _Last
    挿入されるソース範囲内の最後の要素を越えて要素の位置を示す入力反復子、const_pointer、または const_iterator。

戻り値

コンストラクターで作成された String オブジェクトへの参照。

解説

すべてのコンストラクターは basic_string::allocator_type を保存し、被制御シーケンスを初期化します。 アロケーター オブジェクトは、引数 al が指定されていれば、この引数です。 コピー コンストラクターには、right.basic_string::get_allocator()です。 それ以外の場合は Alloc() です。

被制御シーケンスは残りのオペランドで指定されたオペランド シーケンスのコピーに初期化されます。 オペランド シーケンスのコンストラクターは、空の初期被制御シーケンスを指定します。 InputIterator がテンプレートのコンストラクターの整数型である場合、オペランド シーケンス_First, _Last は (size_type)_First, (value_type)_Lastと同様に動作します。

使用例

// basic_string_ctor.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( )
{
   using namespace std;

   // The first member function initializing with a C-string
   const char *cstr1a = "Hello Out There.";
   basic_string <char> str1a ( cstr1a , 5);
   cout << "The string initialized by C-string cstr1a is: "
        << str1a << "." << endl;

   // The second member function initializing with a string
   string  str2a ( "How Do You Do?" );
   basic_string <char> str2b ( str2a , 7 , 7 );
   cout << "The string initialized by part of the string cstr2a is: "
        << str2b << "." << endl;

   // The third member function initializing a string
   // with a number of characters of a specific value
   basic_string <char> str3a ( 5, '9' );
   cout << "The string initialized by five number 9s is: "
        << str3a << endl;

   // The fourth member function creates an empty string
   // and string with a specified allocator
   basic_string <char> str4a;
   string str4b;
   basic_string <char> str4c ( str4b.get_allocator( ) );
   if (str4c.empty ( ) )
      cout << "The string str4c is empty." << endl;
   else
      cout << "The string str4c is not empty." << endl;

   // The fifth member function initializes a string from
   // another range of characters
   string str5a ( "Hello World" );
   basic_string <char> str5b ( str5a.begin ( ) + 5 , str5a.end ( ) );
   cout << "The string initialized by another range is: "
        << str5b << "." << endl;
}

出力

The string initialized by C-string cstr1a is: Hello.
The string initialized by part of the string cstr2a is: You Do?.
The string initialized by five number 9s is: 99999
The string str4c is empty.
The string initialized by another range is:  World.

必要条件

ヘッダー: の <文字列>

名前空間: std

参照

関連項目

basic_string クラス

<string>

左辺値と右辺値

その他の技術情報

basic_string メンバー

<string> メンバー