新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C++ strtok應(yīng)用方式淺析
在C++編程語言中,對(duì)于字符的處理,可以通過使用C++ strtok來進(jìn)行具體的操作。那么正確的應(yīng)用方法我們將會(huì)在這篇文章中為大家詳細(xì)介紹,希望能對(duì)大家有所幫助,提高實(shí)際程序開發(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ù)組格式的.也就是說.入口只能是字符數(shù)組元素地址。
以上就是對(duì)C++ strtok的相關(guān)介紹。
【編輯推薦】
- C++ replace()函數(shù)基本應(yīng)用方法總結(jié)
- C++ CreateThread參數(shù)具體應(yīng)用技巧解析
- C++托管程序?qū)崿F(xiàn)安全管理
- C++文件拷貝應(yīng)用技巧探討
- C++ kmp算法模板代碼解讀
文章題目:C++ strtok應(yīng)用方式淺析
URL鏈接:http://www.5511xx.com/article/dheccij.html


咨詢
建站咨詢
