Answers for "c++ strtok example"

C++
0

strtok in c++

//The strtok() function in C++ returns the next token in a null terminated byte string.
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
    char str[] = "parrot,owl,sparrow,pigeon,crow";
    char delim[] = ",";
    cout << "The tokens are:" << endl;
    char *token = strtok(str,delim);
    while (token)
    {
        cout << token << endl;
        token = strtok(NULL,delim);
    }
    return 0;
}
Posted by: Guest on June-05-2021

Browse Popular Code Answers by Language