std::strncpy
Aus cppreference.com
<metanoindex/>
<tbody> </tbody>| definiert in Header <cstring>
|
||
char *strncpy( char *dest, const char *src, std::size_t count ); |
||
Kopien in den meisten
count Zeichen des Byte-String, auf den src (einschließlich des abschließenden Null-Zeichen), um Zeichen-Array, auf die dest . Original:
Copies at most
count characters of the byte string pointed to by src (including the terminating null character) to character array pointed to by dest. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Wenn
count erreicht wird, bevor der gesamte String src kopiert wurde, ist das resultierende Zeichen-Array nicht null-terminierte .Original:
If
count is reached before the entire string src was copied, the resulting character array is not null-terminated.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Wenn Sie nach dem Kopieren der abschließende Nullzeichen von
src, count nicht erreicht ist, werden zusätzliche null Zeichen dest geschrieben, bis die Summe der count Zeichen geschrieben wurden .Original:
If, after copying the terminating null character from
src, count is not reached, additional null characters are written to dest until the total of count characters have been written.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Wenn die Saiten überlappen, ist das Verhalten undefiniert .
Original:
If the strings overlap, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parameter
| dest | - | Zeiger auf das Zeichen-Array kopiert werden soll
Original: pointer to the character array to copy to The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| src | - | Zeiger auf die Byte-String aus kopieren
Original: pointer to the byte string to copy from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| count | - | maximale Anzahl der zu kopierenden Zeichen
Original: maximum number of characters to copy The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Rückgabewert
dest
Beispiel
#include <iostream>
#include <cstring>
int main()
{
const char* src = "hi";
char dest[6] = {'a', 'b', 'c', 'd', 'e', 'f'};;
std::strncpy(dest, src, 5);
std::cout << "The contents of dest are: ";
for (char c : dest) {
if (c) {
std::cout << c << ' ';
} else {
std::cout << "\\0" << ' ';
}
}
std::cout << '\n';
}
Output:
The contents of dest are: h i \0 \0 \0 f
