char_traits::_Copy_s

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

static char_type *_Copy_s(
    char_type *_Dest,
    size_t _Dest_size,
    const char_type *_From,
    size_t _Count
);

Parameters

  • _Dest
    The string or character array targeted to receive the copied sequence of characters.

  • _Dest_size
    The size of _Dest. If char_type is char, then this size is in bytes. If char_type is wchar_t, then this size is in words.

  • _From
    The source string or character array to be copied.

  • _Count
    The number of elements to be copied.

Return Value

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_s.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_s(s1,
        char_traits<char>::length(s1), s2, 4);
    cout << "The result1 = _Copy_s(s1, "
         << "char_traits<char>::length(s1), s2, 4) is: "
         << result1 << endl;
}

The source string is: abcd-1234-abcd The destination string is: ABCD-1234 The result1 = _Copy_s(s1, char_traits<char>::length(s1), s2, 4) is: ABCD-1234-abcd

Requirements

Header: <string>

Namespace: std

See Also

Reference

char_traits Struct

Safe Libraries: Standard C++ Library

Other Resources

char_traits Members