C++ Code Sample: Split string by space
C++ Code Sample: Split string by space
Mẫu code sample dưới đây sử dụng để tách chuỗi cách nhau bởi dấu space
#include <vector>
#include <string>
std::vector<std::string> SplitBySpace(std::string str)
{
std::vector<std::string> list;
std::string word = "";
for (auto x : str)
{
if (x == ' ')
{
list.push_back(word);
word = "";
}
else
{
word = word + x;
}
}
return list;
}
END
