分割字符串

来源:互联网 发布:js 处理json对象 编辑:程序博客网 时间:2024/05/17 09:20
#include <iostream>#include <cstring>using namespace std;int main(){char sentence[] = "This is a sentence with 7 tokens";cout << "The string to be tokenized is:\n" << sentence << "\n\nThe tokens are:\n\n";char *tokenPtr = strtok(sentence," ");while(tokenPtr != NULL){cout <<tokenPtr << '\n';tokenPtr = strtok(NULL, " ");}cout << "After strtok, sentence = " << sentence <<endl ;return 0;}

原创粉丝点击