char_traits::_Copy_s

复制指定数量的字符从字符串到另一个操作的对象。

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

参数

  • _Dest
    针对的字符串或字符数组接收字符复制的序列。

  • _Dest_size
    _Dest的大小。 如果 char_type 为 char,则此大小 (以字节为单位)。 如果 char_type 为 wchar_t,则此范围。单词。

  • _From
    要复制的源字符串或字符数组。

  • _Count
    要复制的元素的数目。

返回值

针对的字符串或字符数组接收字符复制的序列。

备注

源和目标字符序列不能重叠。

示例

// 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;
}
  

要求

标头:< 字符串>

命名空间: std

请参见

参考

char_traits 结构

安全库:C++ 标准库