Use spaces and commas as delimiters and prints each substring (each token) on its own line: - C++ Data Type

C++ examples for Data Type:char

Description

Use spaces and commas as delimiters and prints each substring (each token) on its own line:

Demo Code

#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;
}

Result


Related Tutorials