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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#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