C++ examples for Data Type:char
Use spaces and commas as delimiters and prints each substring (each token) on its own line:
#include <iostream> #include <cstring> using namespace std; int main()/* ww w . j a v a2 s .com*/ { char the_string[81], *p; cout << "Input a string to parse: "; cin.getline(the_string, 81); p = strtok(the_string, ", "); while (p != nullptr) { cout << p << endl; p = strtok(nullptr, ", "); } return 0; }