Contact: aviboots(AT)netvision.net.il
41,397 questions
53,943 answers
573 users
#include <iostream> #include <sstream> #include <iterator> #include <vector> using namespace std; int main() { char s[] = "C++ C C# Java PHP"; vector<string> tokens; istringstream iss(s); copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(tokens)); for (auto word : tokens) { cout << word << endl; } return 0; } /* run: C++ C C# Java PHP */
#include <iostream> using namespace std; int main() { char s[] = "C++ C C# Java PHP"; char *p; p = strtok(s, " "); while (p != NULL) { cout << p << endl; p = strtok(NULL, " "); } return 0; } /* run: C++ C C# Java PHP */
#include <iostream> using namespace std; int main() { char s[] = "-c, c++.. c# -java ,php...python"; char *p; p = strtok(s, " -.,"); while (p != NULL) { cout << p << endl; p = strtok(NULL, " -.,"); } return 0; } /* run: c c++ c# java php python */