Javatpoint Logo
Javatpoint Logo

C++ String copy()

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

Syntax

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:

Parameter

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.

Output:

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.

Output:

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

Output:

12345

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

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA