朱色虫居
Pages
Home
Featured Posts
2007/05/26
strtok:Split string into tokens
用途:將string切割成tokens
char* strtok(char* str, const char* delimiters)
用法:
#include
using namespace std;
int main(){
char c[20] ="Hello World!"
char *s;
s = strtok(c, " ");
while(s!= NULL){
cout << s << endl; s = strtok(NULL, " "); } }
output:
Hello
World!
也很常看到這樣寫:
for(s=strtok(c," "); s!=NULL; s=strtok(NULL, " "))
cout << s << endl;
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment