C++可以用指针数组从字符串中提取子字符串么?
如果可以请给一个示范QAQ
3条回答 默认 最新
- ysuwood 2015-12-09 14:27关注
http://www.cnblogs.com/xiangzi888/archive/2012/04/16/2451947.html
/* strtok example */ #include <stdio.h> #include <string.h> int main (void) { char str[] = "- This, a sample string."; char *pch; printf("Splitting string \"%s\" into tokens:\n", str); pch = strtok(str," ,.-"); while (pch != NULL) { printf("%s\n", pch); pch = strtok(NULL, " ,.-"); } printf("at the end: %s", str); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报