char_traits::_Move_s
复制指定数量的字符序列中到另一个,能重叠的。
static char_type *_Move_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
从源字符串将复制的元素的数目。
返回值
第一个元素 _Dest 复制到目标的字符串或字符数组接收字符复制的序列。
备注
该源和目标能重叠。
示例
// char_traits__Move_s.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
char_traits<char>::char_type sFrom1[] = "abcd-1234-abcd";
char_traits<char>::char_type sTo1[] = "ABCD-1234";
char_traits<char>::char_type* result1;
cout << "The source string sFrom1 is: " << sFrom1 << endl;
cout << "The destination stringsTo1 is: " << sTo1 << endl;
result1 = char_traits<char>::_Move_s(sTo1,
char_traits<char>::length(sTo1), sFrom1, 4);
cout << "The result1 = _Move_s(sTo1, "
<< "char_traits<char>::length(sTo1), sFrom1, 4) is: "
<< result1 << endl << endl;
// When source and destination overlap
char_traits<char>::char_type sToFrom2[] = "abcd-1234-ABCD";
char_traits<char>::char_type* result2;
cout << "The source/destination string sToFrom2 is: "
<< sToFrom2 << endl;
const char* findc = char_traits<char>::find(sToFrom2, 4, 'c');
result2 = char_traits<char>::_Move_s(sToFrom2,
char_traits<char>::length(sToFrom2), findc, 8);
cout << "The result2 = _Move_s(sToFrom2, "
<< "char_traits<char>::length(sToFrom2), findc, 8) is: "
<< result2 << endl;
}
要求
标头: <string>
命名空间: std