Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++, I am writing a program that ireads pseudocode from a text file. I then w

ID: 648515 • Letter: I

Question

In C++, I am writing a program that ireads pseudocode from a text file. I then will break it up line by line to do operations with. For each line, I will be setting it as a string.

My question is, given a string array of delimiters ( e.g. "(" ")" ";" "," " " each being a string to be used as a delimiter) How can I take the line of text which is a string, and separate it into tokens which are to be stored in their own array?

I have seen examples of tokenizers that use char pointers and other C language style techniques. However, I specifically want to do this using C++ style techniques, and focusing on using functions that are part of the <string> class.

Thanks.

Explanation / Answer

Use the stringtokenizer available in C++.

StringTokenizer strtok(data,":"); is an example where strtok is the name of the string tokenizer. data is the string variable wherein the string to be split is stored and : is the delimiter.