Freigeben über


basic_string::_Copy_s

Kopien höchstens eine bestimmte Anzahl von Zeichen aus einer indizierten Position in einer Quellzeichenfolge zu einem Zielzeichenarray.

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

Parameter

  • _Dest
    Das Zielzeichenarray, in das die Elemente kopiert werden sollen.

  • _Dest_size
    Die Größe von _Dest.

  • _Count
    Die Anzahl von höchstens den von der Quellzeichenfolge kopiert werden Zeichen.

  • _Off
    Die Anfangsposition in der Quellzeichenfolge, von der Kopien gemacht werden sollen.

Rückgabewert

Die Anzahl der Zeichen tatsächlich kopiert.

Hinweise

Ein NULL-Zeichen wird nicht an das Ende der Kopie angefügt.

Beispiel

// 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;
}
  

Anforderungen

Header: <string>

Namespace: std

Siehe auch

Referenz

basic_string Class

Sichere Bibliotheken: C++-Standardbibliothek