Tokenizing a string
Hey, I just moved from C to C++ I got a very small problem.
Say I want to take a fraction as an input -> i.e. 4/8
Is there a way using strings to split it at the '/' or do I need to use C strings?
If so how do I convert them, and do I need to include any C libraries? (string.h for example?)
I have seen some examples but can't get them to work.
Would it be easier (and possible) to take the input in a char* in the first place?
Thanks in advance.
If you trust the user, you can read number << character << number. Check that the character is '/' as a precaution. As far as splitting C++ strings, you've got find and copy
Ok cool, that works
Hopefully I have no more questions but if so I will just update this thread.
Only if the question pertain to this topic should you add them here. Otherwise you are not labelled a spammer for separating new topics into new threads (which is generally better since the boards are also a repository of knowledge).
Also check out the stringstream class.