Monday

C++ using Boost Library: How do I tokenize words from a string in C++?


C++ using Boost Library: How do I tokenize words from a string in C++?

Source Code:

#include <boost/algorithm/string.hpp>

    vector<string> vec_str;

    boost::split(vec_str, "word0 word1 word2", boost::is_space());

    for(size_t i=0; i<vec_str.size(); ++i)
    {
        cout << "vec_str[" << i << "] = " << vec_str[i] << endl;
    }


Output:

vec_str[0] = word0
vec_str[1] = word1
vec_str[2] = word2

No comments:

C++32 (or C++2e), C++ 2032, Cpp 2032, g++ 2032

  Subject: C++ 2032 3 Code example for ? 2 Approximate feature suggestions: - to complete C++29 or C++ 2029 1 Web links, references Wandbox,...