basic_string::copy
원문 문자열의 인덱싱된 위치에서 대상 문자 배열까지 지정된 최대 문자 수를 복사합니다.
This method is potentially unsafe, as it relies on the caller to check that the passed values are correct. 대신 basic_string::_Copy_s를 사용하십시오.
size_type copy(
value_type* _Ptr,
size_type _Count,
size_type _Off = 0
) const;
매개 변수
_Ptr
The target character array to which the elements are to be copied._ Count
The number of characters to be copied, at most, from the source string._Off
The beginning position in the source string from which copies are to be made.
반환 값
The number of characters actually copied.
설명
A null character is not appended to the end of the copy.
예제
// 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