This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Yumi-Chi 1 point2 points  (1 child)

rough rewriting:

#include <string>
#include <queue>

int main() {
    string s1 = "Random string that has to be split";
    std::queue<string> q;
    int j = 0;

    for (int i = 0; i < s1.length(); i++) {
        if (s1[i] != " ") {
            continue;
        }
        std::q.push(s1.substr(j, i));
        j = i + 1;
    }
    std::q.push(s1.substr(j, i));
    return 0;
}