다음을 통해 공유


char_traits::copy

Copies a specified number of characters from one string to another.

This method is potentially unsafe, as it relies on the caller to check that the passed values are correct. 대신 char_traits::_Copy_s를 사용하십시오.

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

매개 변수

  • _To
    The element at the beginning of the string or character array targeted to receive the copied sequence of characters.

  • _From
    The element at the beginning of the source string or character array to be copied.

  • _Num
    The number of elements to be copied.

반환 값

The first element copied into the string or character array targeted to receive the copied sequence of characters.

설명

The source and destination character sequences must not overlap.

예제

// 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 구조체