自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C++ strtok應(yīng)用方式淺析

開發(fā) 后端
C++ strtok的正確應(yīng)用方式是怎樣的?它在實際程序開發(fā)中起來哪些作用。下面就讓我們從一段代碼中來對此進行詳細的解讀。

C++編程語言中,對于字符的處理,可以通過使用C++ strtok來進行具體的操作。那么正確的應(yīng)用方法我們將會在這篇文章中為大家詳細介紹,希望能對大家有所幫助,提高實際程序開發(fā)效率。

C++ strtok原形如下:

  1. char *strtok(  
  2. char *strToken,  
  3. const char *strDelimit   
  4. ); 
  1. // crt_strtok.c  
  2. /**//* In this program, a loop uses strtok  
  3. * to print all the tokens (separated by commas  
  4. * or blanks) in the string named "string".  
  5. */  
  6. #include < string.h> 
  7. #include < stdio.h> 
  8. char string[] = "A string\tof ,,tokens\nand some more tokens";  
  9. char seps[] = " ,\t\n";  
  10. char *token;  
  11. int main( void )  
  12. {  
  13. printf( "Tokens:\n" );  
  14. /**//* Establish string and get the first token: */  
  15. token = strtok( string, seps );  
  16. while( token != NULL )  
  17. {  
  18. /**//* While there are tokens in "string" */  
  19. printf( " %s\n", token );  
  20. /**//* Get next token: */  
  21. token = strtok( NULL, seps );  
  22. }  

C++ strtok輸出:

  1. A  
  2. string  
  3. of  
  4. tokens  
  5. and  
  6. some  
  7. more  
  8. tokens 

Notes:

  1. Strtok(char *strToken, const char *strDelimit ) 

其中,strToken 和 strDelimit 一定要用字符數(shù)組格式的.也就是說.入口只能是字符數(shù)組元素地址。

以上就是對C++ strtok的相關(guān)介紹。

【編輯推薦】

  1. C++ replace()函數(shù)基本應(yīng)用方法總結(jié)
  2. C++ CreateThread參數(shù)具體應(yīng)用技巧解析
  3. C++托管程序?qū)崿F(xiàn)安全管理
  4. C++文件拷貝應(yīng)用技巧探討
  5. C++ kmp算法模板代碼解讀
責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2010-02-03 17:06:36

C++對象復(fù)制

2010-02-05 16:25:10

C++ strtok(

2010-02-05 16:46:58

C++ TinyXml

2010-01-21 09:34:57

C++語法

2010-01-27 16:05:06

C++堆棧

2010-02-04 13:39:44

C++數(shù)組參數(shù)

2010-02-06 16:21:35

C++常規(guī)DLL

2010-02-04 14:29:45

C++ typenam

2010-02-03 15:27:26

C++ static

2010-02-06 16:39:45

C++ assert(

2010-01-22 13:59:34

Visual C++應(yīng)

2010-02-03 10:11:17

C++動態(tài)數(shù)組

2010-01-20 10:19:55

C++數(shù)組

2010-01-27 17:16:52

C++構(gòu)造函數(shù)

2010-02-04 11:15:28

C++模板限制

2010-02-02 14:45:35

C++ typeof

2010-02-05 14:12:46

C++聲明放置

2010-02-03 16:29:19

C++ sizeof

2010-02-05 14:36:20

C++智能指針

2021-10-19 14:04:28

C++類型數(shù)字
點贊
收藏

51CTO技術(shù)棧公眾號