template <typename C, typename T> std::string toString(const C& container, const T& delim)
{
std::stringstream result;
for (auto it = container.begin(); it != container.end(); ++it) {
result << *it;
if (std::distance(it, container.end()) != 1)
result << delim;
}
return result.str();
}
字符串分词Tokenize
std::vector<std::string> tokenize(const std::string& str, const std::string& delimeter)
{
std::vector<std::string> result;
size_t start = str.find_first_not_of(delimeter);
size_t end = start;
while (start != std::string::npos) {
// Find next occurence of delimiter
end = str.find(delimeter, start);
// Push back the token found into vector
result.push_back(str.substr(start, end - start));
// Skip all occurences of the delimiter to find new start
start = str.find_first_not_of(delimeter, end);
}
return result;
}