basic_string::_Copy_s

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

size_type _Copy_s(
    value_type *_Dest,
    size_type _Dest_size,
    size_type _Count,
    size_type _Off = 0
) const;

매개 변수

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

  • _Dest_size
    크기의 _Dest.

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

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

반환 값

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

설명

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

예제

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

int main( )
{
    using namespace std;
    string str1("Hello World");
    basic_string<char>::iterator str_Iter;
    const int array1_size = 20;
    char array1[array1_size] = { 0 };
    const int array2_size = 10;
    char array2[array2_size] = { 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;
    nArray1 = str1._Copy_s(array1Ptr, array1_size, 12);
    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;
    nArray2 = str1._Copy_s(array2Ptr, array2_size, 5, 6);
    cout << "The number of copied characters in array2 is: "
         << nArray2 << endl;
    cout << "The copied characters array2 is: " << array2Ptr << endl;
}
  

요구 사항

헤더: <string>

네임 스페이스: std

참고 항목

참조

basic_string Class

C++ 라이브러리를 표준 안전 라이브러리: