I have a string str="L1 L2 C1 P2 P1 S1 S2" and I would like to store each value into vectors. The following code is what I have attempted to do, when i run the file it crashes.
I am almost sure my error is located in the line " obstypes[i]=p;"
I attempted to use ".push_back" but i faced the same problem.
I strongly recomend using std::string's functions (find() and substr()) but
Let's say you have to use c-style functions and c-style strings. then...
Here are the problems in our code :
1. You don't include <cstring>, this header defines strtok and strcpy.
2. You make a varibale 'i' on line 14, altough you never use it.
3. You don't need a for loop here, you don't need to know how many tokens will be there.
You have to test whether strtok() returns 0.
4. Before the loop you use strtok (line 22), and before you get the results out of p, in the first iteration you overwrite it again (line 33).