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