I want to extract tokens from a given fraction expression, which is passed as a string,
Fraction s("-5 * 7/27");
Where the extracted tokens hold either a single operator or a sequence of digits as an operand, using the stl container only.
May someone guide me to do so? I want to know how to extract the tokens and differentiate the operand from operator, thank you.
Assuming there are always spaces between the tokens, here’s how put them all in a queue:
Running the program will output:
Now to determine which are operators, numbers, or fractions, you can do something like this in the loop:
This website: http://www.cplusplus.com/reference/string/string/ will give you information on the string functions.
After modifying the code and running it again, you’ll get output like this: