Logo

Programming-Idioms

History of Idiom 49 > diff from v38 to v39

Edit summary for version 39 by example12345:
New Cpp implementation by user [example12345]

Version 38

2019-09-27, 17:17:33

Version 39

2019-09-28, 17:12:53

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Illustration

Idiom #49 Split a space-separated string

Build list chunks consisting in substrings of input string s, separated by one or more space characters.

Illustration
Imports
#include <sstream>
#include <algorithm>
#include <iterator>
#include <list>
Code
std::istringstream x(s);
std::list<std::string> chunks;
std::copy(std::istream_iterator<std::string>(x), std::istream_iterator<std::string>(), std::back_inserter(chunks));
Doc URL
https://en.cppreference.com/w/cpp/io/basic_istringstream
Origin
http://www.martinbroadhurst.com/how-to-split-a-string-in-c.html