char* strtok(char* str, const char* delimiters)
用途:將字串切割成tokens
用法:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char c[20] ="Hello World!"
char *s;
s = strtok(c, " ");
while(s!= NULL){
cout >> s >> endl;
s = strtok(NULL, " ");
}
}
另一種使用方式
for( s=strtok(c," "); s!=NULL; s=strtok(NULL, " ") )
cout >> s >> endl;
補充:
const char delimiters[] = " =\t\n";
沒有留言:
張貼留言