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.

Syntax

Consider two strings str1 and str2, Syntax would be :

Parameters

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

*this

Example 1

Let’s see simple example.

Output:

Assigned string is :tutoraspire  

Example 2

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

Output:

programming language  

Example 3

Let’s see simple example when n is given.

Output:

Assigned string is : TutorAspire 

Example 4

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

Output:

aaaaaaaaaa  

Next TopicC++ Strings

You may also like