char_traits::move
复制指定数量的字符序列中到另一个,能重叠的。
此方法是可能不安全的,因此,因为它依赖于调用方检查传递的值是否正确。 请考虑改用 char_traits::_Move_s。
static char_type *move(
char_type* _To,
const char_type* _From,
size_t _Num
);
参数
_To
在面向的字符串或字符数组开头的组件接收字符复制的序列。_From
在要复制的源字符串或字符数组开头的元素。_Num
从源字符串将复制的元素的数目。
返回值
第一个元素 _To 复制到目标的字符串或字符数组接收字符复制的序列。
备注
该源和目标能重叠。
示例
// char_traits_move.cpp
// compile with: /EHsc /W3
#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;
// Note: char_traits::move is potentially unsafe, consider
// using char_traits::_Move_s instead.
result1 = char_traits<char>::move ( sTo1 , sFrom1 , 4 ); // C4996
cout << "The result1 = move ( 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' );
// Note: char_traits::move is potentially unsafe, consider
// using char_traits::_Move_s instead.
result2 = char_traits<char>::move ( sToFrom2 , findc , 8 ); // C4996
cout << "The result2 = move ( sToFrom2 , findc , 8 ) is: "
<< result2 << endl;
}
要求
标头: <string>
命名空间: std