Hello,
I'm creating a sea battle game for a project and at a certain point the user has to enter a string of the following form: 'ship x-coordinate y-coordinate orientation' as many times in a row as he wishsh, e.g. "S5 1 1 v S4 5 4 h S2 1 8 h".
I create extra strings to save every item seperately for further use. But how can I extract them properly one by one? I've been trying for about 2 hours now and I'm starting to run out of ideas .
Here's an example of what I tried. A bit silly code, but for illustration purposes of course.
Obviously that's not really ideal, since the length of every word can vary.Code:std::string s("S5 1 1 v S4 5 4 h S2 1 8 h");while(! s.empty()){ std::string example(s,0,2); s.erase(0,2); }
I thought using getline would be much better, since you can give a parameter when you'd like it to stop (in my case " "). However, I don't know how to get that to work for strings.
Thanks a lot if you can help me out.
Ed.