◐ Shell
clean mode source ↗

std::strncpy - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

Elemento definito nell'header

<cstring>

char *strncpy( char *dest, const char *src, std::size_t count );

Copie a personaggi più count della stringa di byte puntata da src (compreso il carattere di terminazione null) a matrice di caratteri puntato da 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.

Se count viene raggiunto prima della src intera stringa è stato copiato, l'array di caratteri risultante non è con terminazione null.

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.

Se, dopo aver copiato il carattere nullo di terminazione da src, count non viene raggiunto, ulteriori caratteri nulli vengono scritti dest fino al totale di caratteri count sono stati scritti.

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.

Se le stringhe si sovrappongono, il comportamento non è definito.

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.

Parametri

dest -

puntatore alla matrice di caratteri da copiare

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 -

puntatore alla stringa di byte da copiare

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 -

il numero massimo di caratteri da copiare

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.

Valore di ritorno

dest

Esempio

#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

Vedi anche

copia una stringa in un'altra

Original:

copies one string to another

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(funzione) [modifica]

copia un buffer all'altro

Original:

copies one buffer to another

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(funzione) [modifica]

C documentation for strncpy