basic_string::copy

최대 지정한 수의 문자는 인덱스 위치에서 원본 문자열 대상 문자 배열에 복사합니다.

호출자가에 전달 된 값이 올바른지 확인 하므로이 메서드는 잠재적으로 안전 하지 않습니다.대신 basic_string::_Copy_s를 사용하십시오.

size_type copy(
    value_type* _Ptr, 
    size_type _Count,
    size_type _Off = 0
) const;

매개 변수

  • _Ptr
    대상 문자 배열 요소가 복사 됩니다.

  • _ Count
    기껏해야 원본 문자열에서 복사 될 문자 수입니다.

  • _Off
    복사본에는 원본 문자열의 시작 위치입니다.

반환 값

실제로 문자를 복사 합니다.

설명

Null 문자 복사본의 끝에 추가 되지 않습니다.

예제

// basic_string_copy.cpp
// compile with: /EHsc /W3
#include <string>
#include <iostream>

int main( )
{
   using namespace std;
   string str1 ( "Hello World" );
   basic_string <char>::iterator str_Iter;
   char array1 [ 20 ] = { 0 };
   char array2 [ 10 ] = { 0 };
   basic_string <char>:: pointer array1Ptr = array1;
   basic_string <char>:: value_type *array2Ptr = array2;

   cout << "The original string str1 is: ";
   for ( str_Iter = str1.begin( ); str_Iter != str1.end( ); str_Iter++ )
      cout << *str_Iter;
   cout << endl;

   basic_string <char>:: size_type nArray1;
   // Note: string::copy is potentially unsafe, consider
   // using string::_Copy_s instead.
   nArray1 = str1.copy ( array1Ptr , 12 );  // C4996
   cout << "The number of copied characters in array1 is: "
        << nArray1 << endl;
   cout << "The copied characters array1 is: " << array1 << endl;

   basic_string <char>:: size_type nArray2;
   // Note: string::copy is potentially unsafe, consider
   // using string::_Copy_s instead.
   nArray2 = str1.copy ( array2Ptr , 5 , 6  );  // C4996
   cout << "The number of copied characters in array2 is: "
           << nArray2 << endl;
   cout << "The copied characters array2 is: " << array2Ptr << endl;
}
  

요구 사항

헤더: <string>

네임 스페이스: std

참고 항목

참조

basic_string Class