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

std::strtok

Материал из 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* strtok( char* str, const char* delim );
Поиск следующего маркера в нулевым байтом строки, на которую указывает str. Сепаратор символов, определенных нулевым байтом строки, на которую указывает delim.
Original:
Finds the next token in a null-terminated byte string pointed to by str. The separator characters are identified by null-terminated byte string pointed to by delim.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Если str != NULL, функция ищет первый символ, который является не сепаратор. Этот символ начала маркер. Тогда функция ищет первый символ-разделитель. Этот символ конца маркер. Функция завершается и возвращает NULL если конец str встречается до конца маркер не найдено. В противном случае, указатель конца маркер сохраняется в статическом месте для последующих вызовов. Этот символ заменяется на NULL-символа и функция возвращает указатель на начало' маркера.
Original:
If str != NULL, the function searches for the first character which is not separator. This character is the beginning of the token. Then the function searches for the first separator character. This character is the end of the token. Function terminates and returns NULL if end of str is encountered before end of the token is found. Otherwise, a pointer to end of the token is saved in a static location for subsequent invocations. This character is then replaced by a NULL-character and the function returns a pointer to the beginning of the token.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Если str == NULL, функция продолжается, откуда он ушел в предыдущем вызове. Поведение такое же, как если бы ранее сохраненный указатель передается в качестве str.
Original:
If str == NULL, the function continues from where it left in previous invocation. The behavior is the same as if the previously stored pointer is passed as str.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

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

str -
указатель с нулевым байтом строки для маркировки
Original:
pointer to the null-terminated byte string to tokenize
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
delim -
указатель с нулевым байтом строку, идентифицирующую разделители
Original:
pointer to the null-terminated byte string identifying delimiters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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

Указатель на начало маркера, если конец строки не встречается. В противном случае возвращает NULL.
Original:
Pointer to the beginning of a token if the end of string has not been encountered. Otherwise returns NULL.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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

Функция не является потокобезопасным.
Original:
The function is not thread safe.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

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

#include <cstring>
#include <iostream>
 
int main()
{
    char input[100] = "A bird came down the walk";
    char *token = std::strtok(input, " ");
    while (token != NULL) {
        std::cout << token << '\n';
        token = std::strtok(NULL, " ");
    }
}

Вывод:

A
bird
came
down
the
walk

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