How can you cut the format string :

 Haljii Ye Kei M 33 3400$ 

so that similar strings can be sorted by numeric value? In this case, 33 .

One option is to cut the string, put it into an array, and sort the rows according to the desired index. But I don’t know how to cut a string in c ++ . Tell me how you can accomplish this task.

    1 answer 1

    This is how you can divide the string str into substrings, using the delimiter (default - space) as the separator, the vector with substrings will return:

     #include <string> #include <sstream> #include <vector> std::vector<std::string> split(const std::string &str, char delimiter) { std::vector<std::string> tokens; std::stringstream sstr(str); std::string token; while (std::getline(sstr, token, delimiter)) { tokens.push_back(token); } return tokens; } 
    • Thanks, bailed out! :) - Vladislav Solopov