共用方式為


char_traits::copy

複製將指定數目的資料至另一個。

這個方法可能不安全的,因為它,取決於呼叫端檢查傳遞的值是正確的。 因此,請考慮改用 char_traits::_Copy_s

static char_type *copy( 
   char_type* _To,  
   const char_type* _From,  
   size_t _Num  
);

參數

  • _To
    在目標的字串或字元陣列開頭的項目接收字元複製的序列。

  • _From
    要複製的來源字串或字元陣列開頭的項目。

  • _Num
    要複製的元素數。

傳回值

第一個項目複製到目標的字串或字元陣列接收字元複製的序列。

備註

來源和目的字元順序不得重疊。

範例

// char_traits_copy.cpp
// compile with: /EHsc /W3
#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;
   // Note: char_traits::copy is potentially unsafe, consider
   // using char_traits::_Copy_s instead.
   result1 = char_traits<char>::copy ( s1 , s2 , 4 );  // C4996
   cout << "The result1 = copy ( s1 , s2 , 4 ) is: "
        << result1 << endl;
}
  

需求

標頭:<string>

命名空間: std

請參閱

參考

char_traits 結構