掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
在C++編程語(yǔ)言中,對(duì)于字符的處理,可以通過(guò)使用C++ strtok來(lái)進(jìn)行具體的操作。那么正確的應(yīng)用方法我們將會(huì)在這篇文章中為大家詳細(xì)介紹,希望能對(duì)大家有所幫助,提高實(shí)際程序開(kāi)發(fā)效率。

C++ strtok原形如下:
- char *strtok(
- char *strToken,
- const char *strDelimit
- );
- // crt_strtok.c
- /**//* In this program, a loop uses strtok
- * to print all the tokens (separated by commas
- * or blanks) in the string named "string".
- */
- #include < string.h>
- #include < stdio.h>
- char string[] = "A string\tof ,,tokens\nand some more tokens";
- char seps[] = " ,\t\n";
- char *token;
- int main( void )
- {
- printf( "Tokens:\n" );
- /**//* Establish string and get the first token: */
- token = strtok( string, seps );
- while( token != NULL )
- {
- /**//* While there are tokens in "string" */
- printf( " %s\n", token );
- /**//* Get next token: */
- token = strtok( NULL, seps );
- }
- }
C++ strtok輸出:
- A
- string
- of
- tokens
- and
- some
- more
- tokens
Notes:
- Strtok(char *strToken, const char *strDelimit )
其中,strToken 和 strDelimit 一定要用字符數(shù)組格式的.也就是說(shuō).入口只能是字符數(shù)組元素地址。
以上就是對(duì)C++ strtok的相關(guān)介紹。
【編輯推薦】

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流