There are situations when we need to split some strings into substrings and do something with those substrings. In this recipe, we want to split string into sentences, count characters, and white-spaces and, of course, we want to use Boost and be as efficient as possible.
That's very easy to do with Boost:
- First of all, include the right headers:
#include <iostream> #include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/classification.hpp> #include <algorithm>
- Now, let's define our test string:
int main() { const char str[] = "This is a long long character array." "Please split this character array to sentences!" "Do you know, that sentences are separated using period, " "exclamation mark and question mark? :-)" ;
- We make a
typedef
for our splitting iterator:
...