Javatpoint Logo
Javatpoint Logo

C++ String copy()

This function copies the contents of one string into another string.


Suppose str1 and str2 are two string objects, len is the length of substring. We want to copy string str1 into the string object str2 then the syntax would look like:


str2: str2 is the destination string object which retains the copied string.

len: It defines the length of substring.

pos: It determines the position of first character to include.

Return value

It returns the number of characters to be copied.

Example 1

Let's see a simple example of copying the string into another string object.


source string is: javatpoint tutorial
destination string is: javatpoint tutorial 

In this example, source string contains the value "javatpoint tutorial" and we copy the source string to the destination string using copy function.

Example 2

Let's see a simple example of copying the string when position is passed in a parameter.


String contains: programs

In this example, we copy the substring of string str i.e. programs to the string str1 using copy function.

Example 3

Let's see a simple example of copying the array of integers in vector



In this example, we copy the array of integers to the vector using copy function.

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