c++ split string by space into array

include

include

include

include

int main() { std::string str = "Hello world, this is a sample string"; std::vector words; std::stringstream ss(str); std::string word;

while (ss >> word) { words.push_back(word); }

for (const auto &w : words) { std::cout << w << std::endl; }

return 0; }