public member function
std::string::operator=
<string>
string& operator= ( const string& str );
string& operator= ( const char* s );
string& operator= ( char c );
String assignment
Sets a copy of the argument as the new content for the
string object.
The previous content is dropped.
The
assign member function provides a similar functionality with additional options.
Parameters
- str
- string object. A copy of the content of this object is used as the new content for the object.
- s
- A pointer to an array containing a null-terminated character sequence (C string), which is copied as the new content for the object.
- c
- Character. The content is set to a single character.
Return Value
*this
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// string assigning
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str1, str2, str3;
str1 = "Test string: "; // c-string
str2 = 'x'; // single character
str3 = str1 + str2; // string
cout << str3 << endl;
return 0;
}
|
Output:
Basic template member declarations
( basic_string<charT,traits,Allocator> )
1 2 3 4 5
|
basic_string<charT,traits,Allocator>&
operator= ( const basic_string<charT,traits,Allocator>& str );
basic_string<charT,traits,Allocator>&
operator= ( const charT* s );
basic_string<charT,traits,Allocator>& operator= ( char c );
|
See also
- string::assign
- Assign content to string (public member function)
- string::operator+=
- Append to string (public member function)
- string::insert
- Insert into string (public member function)
- string::replace
- Replace part of string (public member function)
- string::string
- Construct string object (public member function)
- string::compare
- Compare strings (public member function)