<string>
ãããã«ããstd::getline()
é¢æ°ã¯ãè¡åä½ã®èªã¿åãã ãã§ãªããåºåãæåãæå®ãããã¼ã¸ã§ã³ãããã®ã§ãsplitã®å®è£
ã«ä½¿ãããããã
#include <iostream> #include <string> #include <sstream> #include <vector> std::vector<std::string> split(const std::string& input, char delimiter) { std::istringstream stream(input); std::string field; std::vector<std::string> result; while (std::getline(stream, field, delimiter)) { result.push_back(field); } return result; } int main() { const std::string input = "aaa,bbb,ccc"; for (const std::string& s : split(input, ',')) { std::cout << s << std::endl; } }
åºåï¼
aaa bbb ccc