std::strncpy
Da cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <cstring>
|
||
| char *strncpy( char *dest, const char *src, std::size_t count ); |
||
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.
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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
Índice |
[editar] 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. You can help to correct and verify the translation. Click here for instructions. |
| 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. You can help to correct and verify the translation. Click here for instructions. |
| 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. You can help to correct and verify the translation. Click here for instructions. |
[editar] Valor de retorno
dest
[editar] 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'; }
Output:
The contents of dest are: h i \0 \0 \0 f
[editar] Veja também
| copia uma string para outra 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. (função) | |
| copia um buffer para outro 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. (função) | |
| C documentation for strncpy
| |