std::strtok
来自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* strtok( char* str, const char* delim ); |
||
。寻找下一个标记指向一个空终止字节的字符串,在
str。分隔字符识别null结尾的字节串所指向的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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 。参数。
| str | - | 。指针null结尾的字节串来标记。
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 | - | 。 null结尾的字节串识别分隔符的指针。
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.
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.
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, " "); } }
Output:
A bird came down the walk
[编辑] 。另请参阅。
| C documentation for strtok
|