C++ split字符串

来源:互联网 发布:mac vnc连接windows 编辑:程序博客网 时间:2024/06/02 07:27
#include <stdio.h>#include <string.h>int main (){  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, " ,.-");  }  return 0;}