1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 int main() 7 { 8 string s; 9 getline(cin,s); // 读取一行 10 char *p; // 存储分割完一次分出的字符数组 11 char *ss = const_cast<char *>(s.c_str() ); 12 p = strtok(ss," "); 13 while(p) 14 { 15 cout << p << "----"; 16 p = strtok(NULL," "); 17 } 18 cout << endl << s << endl << ss << endl; 19 return 0; 20 }
原文:https://www.cnblogs.com/limancx/p/13061482.html