It appends character c to the end of the string, increasing its length by one.
DeclarationFollowing is the declaration for std::string::assign.
string& assign (const string& str);C++11
string& assign (const string& str);C++14
string& assign (const string& str);Parameters
c − It is a character object.
str − It is a string object.
It returns *this.
Exceptionsif an exception is thrown, there are no changes in the string.
ExampleIn below example for std::string::assign.
#include <iostream> #include <string> int main () { std::string str; std::string base="Sairamkrishna is a one of the tech person in tutorialspoint."; str.assign(base); std::cout << str << '\n'; str.assign(base,10,9); std::cout << str << '\n'; str.assign("pangrams are cool",7); std::cout << str << '\n'; str.assign("c-string"); std::cout << str << '\n'; str.assign(10,'*'); std::cout << str << '\n'; str.assign<int>(10,0x2D); std::cout << str << '\n'; str.assign(base.begin()+16,base.end()-12); std::cout << str << '\n'; return 0; }
The sample output should be like this −
Sairamkrishna is a one of the tech person in tutorialspoint. hna is a pangram c-string ********** ---------- a one of the tech person in tut
string.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4