Javatpoint Logo
Javatpoint Logo

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 :javatpoint

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 : javatpoint

Example 4

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



Next TopicC++ Strings

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA