Пространства имён
Варианты
Действия

std::strncpy

Материал из cppreference.com

 
 
 
Нульзаканчивающихся строк байт
Функции
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Персонаж манипуляции
Original:
Character manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Преобразование в цифровой формат
Original:
Conversions to numeric formats
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Строками
Original:
String manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
strcpy
strncpy
strcat
strncat
strxfrm
Струнный экспертизы
Original:
String examination
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Память манипуляции
Original:
Memory manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memchr
memcmp
memset
memcpy
memmove
Разное
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
strerror
 
Заголовочный файл <cstring>
char *strncpy( char *dest, const char *src, std::size_t count );
Копии не более count символов байт строки, на которую указывает src (включая завершающий нулевой символ) в массив символов, на которую указывает 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.
Если count будет достигнута до того, как весь src строки были скопированы, в результате массив символов не является нулем.
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.
Если после копирования завершающий нулевой символ из src, count не достигнута, дополнительные нулевые символы записываются в dest до всего count символы были написаны.
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.
Если строки перекрываются, поведение не определено.
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.

Содержание

[править] Параметры

dest -
Указатель на массив символов для копирования
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 -
Указатель на строку байтов для копирования с
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 -
Максимальное количество символов для копирования
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.

[править] Возвращаемое значение

dest

[править] Пример

#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';
}

Вывод:

The contents of dest are: h i \0 \0 \0 f

[править] См. также

копирует одну строку в другую
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.

(функция) [edit]
копия одного буфера в другой
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.

(функция) [edit]