The wcstok() function is defined in cwchar.h header file. The wcstok() function returns the next token in a null terminated wide string. The pointer delim points to the separator characters i.e. the delimeter.
Syntax:
wchar_t* wcstok(wchar_t* str,
const wchar_t* delim,
wchar_t ** ptr);
Parameters: This method takes following paramters:
- str: It represents pointer to the null-terminated wide string to tokenize.
- delim: It represents pointer to the null terminated wide string that contains the separators.
- ptr: It represents pointer to an object of type wchar_t*, which is used by wcstok to store its internal state.
Return Value: The wcstok() function returns the pointer to the beginning of next token if there is any. Otherwise it returns zero.
Below program illustrate the above function:
Example 1:
// c++ program to demonstrate // example of wcstok() function. #include <bits/stdc++.h> using namespace std; int main() { // Get the string wchar_t str[] = L"A computer science portal for geeks"; // Creating the parameters of wcstok() method // Create the pointer of which // the next token is required wchar_t* ptr; // Define the delimeter of the string wchar_t delim[] = L" "; // Call the wcstok() method wchar_t* token = wcstok(str, delim, &ptr;); // Print all tokens with the help of it while (token) { wcout << token << endl; token = wcstok(NULL, delim, &ptr;); } return 0; } |
A computer science portal for geeks
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
Recommended Posts:
- Function Interposition in C with an example of user defined malloc()
- tellg() function in C++ with example
- wcsstr() function in C++ with example
- wcsncpy() function in C++ with example
- Buffer Overflow Attack with Example
- ftell() in C with example
- fseek() in C/C++ with example
- Writing first C++ program : Hello World example
- std::search_n with example in C++
- tellp() in file handling with c++ with example
- vector::crend() & vector::crbegin() with example
- forward_list::cend() in C++ STL with Example
- Vector removeElement() method in Java with Example
- Vector removeRange() method in Java with Example
- Vector toString() method in Java with Example
- Vector setSize() method in Java with Example
- Vector trimToSize() method in Java with Example
- ConcurrentLinkedDeque peek() method in Java with Example
- ConcurrentLinkedDeque poll() method in Java with Example
- Vector setElementAt() method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

