This documentation is archived and is not being maintained.

char_traits::copy

Copies a specified number of characters from one string to another.

static char_type *copy(
   char_type* _To, 
   const char_type* _From, 
   size_t _Num 
);

Parameters

_To
The element at the beginning of the string or character array targeted to receive the copied sequence of characters.
_From
The element at the beginning of the source string or character array to be copied.
_Num
The number of elements to be copied.

Return Value

The first element copied into the string or character array targeted to receive the copied sequence of characters.

Remarks

The source and destination character sequences must not overlap.

Example

// char_traits_copy.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   char_traits<char>::char_type s1[] = "abcd-1234-abcd";
   char_traits<char>::char_type s2[] = "ABCD-1234";
   char_traits<char>::char_type* result1;
   cout << "The source string is: " << s1 << endl;
   cout << "The destination string is: " << s2 << endl;
   result1 = char_traits<char>::copy ( s1 , s2 , 4 );
   cout << "The result1 = copy ( s1 , s2 , 4 ) is: "
        << result1 << endl;
}

Output

The source string is: abcd-1234-abcd
The destination string is: ABCD-1234
The result1 = copy ( s1 , s2 , 4 ) is: ABCD-1234-abcd

See Also

char_traits Class | char_traits Members

Show: