O'Reilly logo

Boost C++ Application Development Cookbook by Antony Polukhin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Representing a string with two iterators

There are situations when we need to split some strings into substrings and do something with those substrings. For example, count whitespaces in the string and, of course, we want to use Boost and be as efficient as possible.

Getting ready

You'll need some basic knowledge of STL algorithms for this recipe.

How to do it...

We won't be counting whitespaces; instead we'll split the string into sentences. You'll see that it is very easy with Boost.

  1. First of all, include the right headers:
    #include <boost/algorithm/string/split.hpp>
    #include <boost/algorithm/string/classification.hpp>
    #include <algorithm>
  2. Now let's define our test string:
    int main() { const char str[] = "This is a long long character array." "Please ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required