The pop_back() call from line 21 causes unhandled exception std::out_of_range. Doing x.erase(x.end() - 2, x.end()); instead of the two pop_backs causes the same thing. This means there is a problem with the forelast character in x. What is wrong ?
What a shame, that was the problem indeed. It seems the first string returned from "tasklist" command is only containing a newline character. I had no idea.