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
);
매개 변수
_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.
반환 값
The string or character array targeted to receive the copied sequence of characters.
설명
The source and destination character sequences must not overlap.
예제
// 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;
}
요구 사항
헤더: <string>
네임스페이스: std