#include#include #include using namespace std; int main() { string str = "apple,banana,orange"; vector arr; // Split the string into tokens based on comma delimiter and add them to the array str.addTokens(arr, ","); // Print the array of strings for (int i = 0; i < arr.size(); i++) { cout << arr[i] << endl; } return 0; }
#includeIn both examples, we use the addTokens method to split the input string into tokens based on the specified delimiter ("," and " " respectively) and add those tokens to an array of strings. We then print out the contents of the string array to verify that the tokens were correctly created and added. The package library used in these examples is the C++ Standard Library.#include #include using namespace std; int main() { string str = "The quick brown fox jumps over the lazy dog"; vector arr; // Split the string into tokens based on space delimiter and add them to the array str.addTokens(arr, " "); // Print the array of strings for (int i = 0; i < arr.size(); i++) { cout << arr[i] << endl; } return 0; }