c++ 中写一段用来分割文本的代码 比如有一个文本 QString t=你好我是懒人天天向上 用 进行切割然后返回数组 不要用vector
#include
using namespace std;
int main() { string t = "你好,我是,懒人,天天,向上"; char *cstr = new char[t.length() + 1]; strcpy(cstr, t.c_str());
char *p = strtok(cstr, ",");
while (p != NULL)
{
cout << p << endl;
p = strtok(NULL, ",");
}
delete[] cstr;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/cjzw 著作权归作者所有。请勿转载和采集!