C++ tutorial-assign() function
C++ String Manipulation
C++ assign() function
function is used to assign all characters of a string to another string or just part of a string to another string. Normally, you can assign one string to another by using assignment operator(=). However, if you want to assign a proportion of a string to another string you need to you the assign() function instead. The assign() function has two forms. The first form is to assign all characters from a string to another and the second form assigns part of a string to another string.
assign(string, start, num_chars);
The second form of the assign() function accepts three arguments. The first argument is a string that you want to cut part of it and the start argument indicates where you want to start cutting. The num_chars argument is about the number of characters that you want to cut.
using namespace std;
string str2="C++ programming code";
str1.assign(str2);//assign entire string str2 to another string str1
str1.assign(str2,4,11);//assign part of string str 2 to another string str1