Home » C++ String assign() function

C++ String assign() function

by Online Tutorials Library

C++ String Assign()

This functions assigns a new value to the string,replacing all its current contents.


Consider two strings str1 and str2, Syntax would be :


str : str is a string object, whose value to be assigned.

subpos : It defines the position of the character which is to be copied as a substring.

sublen : It determines the number of characters of string to be copied in another string object.

n : Number of characters to copy.

ch : Character value to be copied n times

Return value


Example 1

Let’s see simple example.


Assigned string is :tutoraspire  

Example 2

Let’s see simple example when position and length are mentioned in the parameters.


programming language  

Example 3

Let’s see simple example when n is given.


Assigned string is : TutorAspire 

Example 4

Let’s see simple example when character value is given in a parameter.



Next TopicC++ Strings

You may also like