basic_string::operator=
文字列の内容に新しい文字の値を割り当てます。
basic_string<CharType, Traits, Allocator>& operator=(
value_type _Ch
);
basic_string<CharType, Traits, Allocator>& operator=(
const value_type* _Ptr
);
basic_string<CharType, Traits, Allocator>& operator=(
const basic_string<CharType, Traits, Allocator>& _Right
);
basic_string<CharType, Traits, Allocator>& operator=(
const basic_string<CharType, Traits, Allocator>&& _Right
);
パラメーター
_Ch
割り当てる文字値。_Ptr
対象文字列に割り当てる C 文字列内の文字へのポインター。_Right
文字は、対象の文字列に割り当てられたソース文字列。
戻り値
メンバー関数によって新しい文字が割り当てられている文字列オブジェクトへの参照。
解説
文字列を新しい文字値が割り当てられることがあります。 新しい値は、C 文字列または一つの文字である場合があります。 operator= は新しい値が単一のパラメーターで記述できる場合に使用される可能性がある文字列内の部分文字列は対象に割り当てるかを指定するために、複数のパラメーターを持つメンバー関数 割り当てが使用される場合があります。
使用例
// basic_string_op_assign.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
// The first member function assigning a
// character of a certain value to a string
string str1a ( "Hello " );
str1a = '0';
cout << "The string str1 assigned with the zero character is: "
<< str1a << endl << endl;
// The second member function assigning the
// characters of a C-string to a string
string str1b;
const char *cstr1b = "Out There";
cout << "The C-string cstr1b is: " << cstr1b << "." << endl;
str1b = cstr1b;
cout << "Assigning the C-string cstr1a to string str1 gives: "
<< str1b << "." << endl << endl;
// The third member function assigning the characters
// from one string to another string in two equivalent
// ways, comparing the assign and operator =
string str1c ( "Hello" ), str2c ( "Wide" ), str3c ( "World" );
cout << "The original string str1 is: " << str1c << "." << endl;
cout << "The string str2c is: " << str2c << "." << endl;
str1c.assign ( str2c );
cout << "The string str1 newly assigned with string str2c is: "
<< str1c << "." << endl;
cout << "The string str3c is: " << str3c << "." << endl;
str1c = str3c;
cout << "The string str1 reassigned with string str3c is: "
<< str1c << "." << endl << endl;
}
必要条件
ヘッダー: の <文字列>
名前空間: std