std::strncpy - cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Definido no cabeçalho <cstring> |
||
|
|
||
Cópias de personagens mais count da cadeia de bytes apontado por src (incluindo o caractere nulo de terminação) a matriz de caracteres apontada por 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 for atingido antes da src cadeia inteira foi copiado, a matriz de caracteres resultante não é nulo terminada.
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, depois de copiar o caractere nulo de terminação de src, count não for alcançado, outros caracteres nulos são escritos para dest até que o total de caracteres count ter sido escrita.
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 as cordas se sobrepõem, o comportamento é indefinido.
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.
Parâmetros
| dest | - | ponteiro para a matriz de caracteres para copiar Original: pointer to the character array to copy to The text has been machine-translated via Google Translate. |
| src | - | ponteiro para o byte string para copiar Original: pointer to the byte string to copy from The text has been machine-translated via Google Translate. |
| count | - | número máximo de caracteres a serem copiados Original: maximum number of characters to copy The text has been machine-translated via Google Translate. |
Valor de retorno
dest
Exemplo
#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'; }
Saída:
The contents of dest are: h i \0 \0 \0 f
Veja também
copia uma string para outra Original: copies one string to another The text has been machine-translated via Google Translate. (função) [edit] | |
copia um buffer para outro Original: copies one buffer to another The text has been machine-translated via Google Translate. (função) [edit] | |
Documentação C para strncpy | |