string copy() in C++

copy(): Copy substring into C string. It returns a number of characters 

actually copied.

This function is available in the below file.

File: basic_string.tcc

Parameters: 

__s:– C string to copy the value into. 

__n: – Number of characters to copy.

 __pos:– Index of the first character to copy.

Syntax:

str.copy(__s, __n, __pos)

For Example:

str = "abc"

__s = "def"

str.copy(__s,4,0) => It returns 3.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str = "abc";
    char str2[] = "def";

    cout << str.copy(str240<< "\n";

    

    return 0;
}


No comments:

Post a Comment