Apis

boost/algorithm/string/case_conv.hpp

  • to_lower()
  • to_lower_copy()
  • to_upper()
  • to_upper_copy()

boost/algorithm/string/predicate.hpp

  • starts_with()
  • istarts_with()
  • ends_with()
  • iends_with()
  • contains()
  • icontains()
  • equals()
  • iequals()
  • lexicographical_compare()
  • ilexicographical_compare()
  • all()

boost/algorithm/string/classification.hpp

  • is_classified()
  • is_space()
  • is_alnum()
  • is_alpha()
  • is_cntrl()
  • is_digit()
  • is_graph()
  • is_lower()
  • is_print()
  • is_punct()
  • is_upper()
  • is_xdigit()

boost/algorithm/string/trim.hpp

  • trim_left_copy_if()
  • trim_left_copy()
  • trim_left_if()
  • trim_left()
  • trim_right_copy_if()
  • trim_right_copy()
  • trim_right_if()
  • trim_right()
  • trim_copy_if()
  • trim_copy()
  • trim_if()
  • trim()

boost/algorithm/string/find.hpp

  • find()
  • find_first()
  • ifind_first()
  • find_last()
  • ifind_last()
  • find_nth()
  • ifind_nth()
  • find_head()
  • find_tail()
  • find_token()

boost/algorithm/string/replace.hpp

  • replace_range_copy()
  • replace_range()
  • replace_first_copy()
  • replace_first()
  • ireplace_first_copy()
  • ireplace_first()
  • replace_last_copy()
  • replace_last()
  • ireplace_last_copy()
  • ireplace_last()
  • replace_nth_copy()
  • replace_nth()
  • ireplace_nth_copy()
  • ireplace_nth()
  • replace_all_copy()
  • replace_all()
  • ireplace_all_copy()
  • ireplace_all()
  • replace_head_copy()
  • replace_head()
  • replace_tail_copy()
  • replace_tail()

boost/algorithm/string/erase.hpp

  • erase_range_copy()
  • erase_range()
  • erase_first_copy()
  • erase_first()
  • ierase_first_copy()
  • ierase_first()
  • erase_last_copy()
  • erase_last()
  • ierase_last_copy()
  • ierase_last()
  • erase_nth_copy()
  • erase_nth()
  • ierase_nth_copy()
  • ierase_nth()
  • erase_all_copy()
  • erase_all()
  • ierase_all_copy()
  • ierase_all()
  • erase_head_copy()
  • erase_head()
  • erase_tail_copy()
  • erase_tail()

boost/algorithm/string/find_format.hpp

  • find_format_copy()
  • find_format()
  • find_format_all_copy()
  • find_format_all()

boost/algorithm/string/find_iterator.hpp

  • make_find_iterator()
  • make_split_iterator()

boost/algorithm/string/split.hpp

  • find_all()
  • ifind_all()
  • split()

Quick Reference

Case Conversion

Algorithm name Description Functions
to_upper Convert a string to upper case
  • [to_upper_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/to_upper_copy.html)
  • [to_upper()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/to_upper.html)
to_lower Convert a string to lower case
  • [to_lower_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/to_lower_copy.html)
  • [to_lower()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/to_lower.html)

Trimming

Algorithm name Description Functions
trim_left Remove leading spaces from a string
  • [trim_left_copy_if()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_left_copy_if.html)
  • [trim_left_if()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_left_if.html)
  • [trim_left_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_left_copy.html)
  • [trim_left()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_left.html)
trim_right Remove trailing spaces from a string
  • [trim_right_copy_if()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_right_copy_if.html)
  • [trim_right_if()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_right_if.html)
  • [trim_right_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_right_copy.html)
  • [trim_right()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_right.html)
trim Remove leading and trailing spaces from a string
  • [trim_copy_if()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_copy_if.html)
  • [trim_if()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_if.html)
  • [trim_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim_copy.html)
  • [trim()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/trim.html)

Predicates

Algorithm name Description Functions
starts_with Check if a string is a prefix of the other one
  • [starts_with()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/starts_with.html)
  • [istarts_with()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/istarts_with.html)
ends_with Check if a string is a suffix of the other one
  • [ends_with()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ends_with.html)
  • [iends_with()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/iends_with.html)
contains Check if a string is contained of the other one
  • [contains()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/contains.html)
  • [icontains()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/icontains.html)
equals Check if two strings are equal
  • [equals()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/equals.html)
  • [iequals()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/iequals.html)
lexicographical_compare Check if a string is lexicographically less then another one
  • [lexicographical_compare()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/lexicographical_compare.html)
  • [ilexicographical_compare()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ilexicographical_compare.html)
all Check if all elements of a string satisfy the given predicate
  • [all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/all.html)

Find algorithm

Algorithm name Description Functions
find_first Find the first occurrence of a string in the input
  • [find_first()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_first.html)
  • [ifind_first()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ifind_first.html)
find_last Find the last occurrence of a string in the input
  • [find_last()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_last.html)
  • [ifind_last()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ifind_last.html)
find_nth Find the nth (zero-indexed) occurrence of a string in the input
  • [find_nth()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_nth.html)
  • [ifind_nth()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ifind_nth.html)
find_head Retrieve the head of a string
  • [find_head()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_head.html)
find_tail Retrieve the tail of a string
  • [find_tail()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_tail.html)
find_token Find first matching token in the string
  • [find_token()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_token.html)
find_regex Use the regular expression to search the string
  • [find_regex()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_regex.html)
find Generic find algorithm
  • [find()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find.html)

Erase/Replace

Algorithm name Description Functions
replace/erase_first Replace/Erase the first occurrence of a string in the input
  • [replace_first()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_first.html)
  • [replace_first_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_first_copy.html)
  • [ireplace_first()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_first.html)
  • [ireplace_first_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_first_copy.html)
  • [erase_first()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_first.html)
  • [erase_first_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_first_copy.html)
  • [ierase_first()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_first.html)
  • [ierase_first_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_first_copy.html)
replace/erase_last Replace/Erase the last occurrence of a string in the input
  • [replace_last()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_last.html)
  • [replace_last_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_last_copy.html)
  • [ireplace_last()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_last.html)
  • [ireplace_last_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_last_copy.html)
  • [erase_last()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_last.html)
  • [erase_last_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_last_copy.html)
  • [ierase_last()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_last.html)
  • [ierase_last_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_last_copy.html)
replace/erase_nth Replace/Erase the nth (zero-indexed) occurrence of a string in the input
  • [replace_nth()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_nth.html)
  • [replace_nth_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_nth_copy.html)
  • [ireplace_nth()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_nth.html)
  • [ireplace_nth_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_nth_copy.html)
  • [erase_nth()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_nth.html)
  • [erase_nth_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_nth_copy.html)
  • [ierase_nth()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_nth.html)
  • [ierase_nth_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_nth_copy.html)
replace/erase_all Replace/Erase the all occurrences of a string in the input
  • [replace_all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_all.html)
  • [replace_all_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_all_copy.html)
  • [ireplace_all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_all.html)
  • [ireplace_all_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ireplace_all_copy.html)
  • [erase_all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_all.html)
  • [erase_all_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_all_copy.html)
  • [ierase_all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_all.html)
  • [ierase_all_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ierase_all_copy.html)
replace/erase_head Replace/Erase the head of the input
  • [replace_head()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_head.html)
  • [replace_head_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_head_copy.html)
  • [erase_head()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_head.html)
  • [erase_head_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_head_copy.html)
replace/erase_tail Replace/Erase the tail of the input
  • [replace_tail()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_tail.html)
  • [replace_tail_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_tail_copy.html)
  • [erase_tail()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_tail.html)
  • [erase_tail_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_tail_copy.html)
replace/erase_regex Replace/Erase a substring matching the given regular expression
  • [replace_regex()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_regex.html)
  • [replace_regex_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_regex_copy.html)
  • [erase_regex()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_regex.html)
  • [erase_regex_copy](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_regex_copy.html)
replace/erase_regex_all Replace/Erase all substrings matching the given regular expression
  • [replace_all_regex()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_all_regex.html)
  • [replace_all_regex_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/replace_all_regex_copy.html)
  • [erase_all_regex()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_all_regex.html)
  • [erase_all_regex_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/erase_all_regex_copy.html)
find_format Generic replace algorithm
  • [find_format()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_format.html)
  • [find_format_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_format_copy.html)
  • [find_format_all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_format_all.html)
  • [find_format_all_copy()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_format_all_copy.html)

Split

Algorithm name Description Functions
find_all Find/Extract all matching substrings in the input
  • [find_all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_all.html)
  • [ifind_all()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/ifind_all.html)
  • [find_all_regex()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/find_all_regex.html)
split Split input into parts
  • [split()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/split.html)
  • [split_regex()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/split_regex.html)
iter_find Iteratively apply the finder to the input to find all matching substrings
  • [iter_find()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/iter_find.html)
iter_split Use the finder to find matching substrings in the input and use them as separators to split the input into parts
  • [iter_split()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/iter_split.html)

Join

Algorithm name Description Functions
join Join all elements in a container into a single string
  • [join()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/join.html)
join_if Join all elements in a container that satisfies the condition into a single string
  • [join_if()](https://www.boost.org/doc/libs/1_75_0/doc/html/boost/algorithm/join_if_1_3_3_9_14_3_1_2.html)

Finders and Formatters

Finder Description Generators
first_finder Search for the first match of the string in an input first_finder()
last_finder Search for the last match of the string in an input last_finder()
nth_finder Search for the nth (zero-indexed) match of the string in an input nth_finder()
head_finder Retrieve the head of an input head_finder()
tail_finder Retrieve the tail of an input tail_finder()
token_finder Search for a matching token in an input token_finder()
range_finder Do no search, always returns the given range range_finder()
regex_finder Search for a substring matching the given regex regex_finder()
Formatter Description Generators
const_formatter Constant formatter. Always return the specified string const_formatter()
identity_formatter Identity formatter. Return unmodified input identity_formatter()
empty_formatter Null formatter. Always return an empty string empty_formatter()
regex_formatter Regex formatter. Format regex match using the specification in the format string regex_formatter()

Iterator

Iterator name Description Iterator class
find_iterator Iterates through matching substrings in the input find_iterator
split_iterator Iterates through gaps between matching substrings in the input split_iterator

Classification

Predicate name Description Generator
is_classified Generic ctype mask based classification is_classified()
is_space Recognize spaces is_space()
is_alnum Recognize alphanumeric characters is_alnum()
is_alpha Recognize letters is_alpha()
is_cntrl Recognize control characters is_cntrl()
is_digit Recognize decimal digits is_digit()
is_graph Recognize graphical characters is_graph()
is_lower Recognize lower case characters is_lower()
is_print Recognize printable characters is_print()
is_punct Recognize punctuation characters is_punct()
is_upper Recognize uppercase characters is_upper()
is_xdigit Recognize hexadecimal digits is_xdigit()
is_any_of Recognize any of a sequence of characters is_any_of()
is_from_range Recognize characters inside a min..max range is_from_range()

Examples

code repo: https://github.com/busyboxs/boost-learn

Convert example

#include <string>
#include <vector>
#include <iostream>
#include <iterator>
#include <boost/algorithm/string/case_conv.hpp>

int main()
{
std::cout << "* Case Conversion Example *" << std::endl << std::endl;

std::string str1("AbCdEfG");
std::vector<char> vec1(str1.begin(), str1.end());

std::cout << "lower-cased copy of vec1: ";
boost::to_lower_copy(std::ostream_iterator<char>(std::cout), vec1);
std::cout << std::endl;

std::cout << "upper-cased copy of str1:" << boost::to_upper_copy(str1) << std::endl;

boost::to_lower(str1);
std::cout << "lower-cased str1: " << str1 << std::endl;

boost::to_upper(str1);
std::cout << "then to upper case: " << str1 << std::endl;

std::cout << std::endl;

return 0;
}

trim example

#include <string>
#include <iostream>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/classification.hpp>

int main()
{
std::cout << "* Trim Example *" << std::endl << std::endl;

std::string str1(" 1x x x x1 ");
std::string str2("<>trim<>");
std::string str3("123abs123");

std::cout << "trim_left copy of str1: [" << boost::trim_left_copy(str1) << "]" << std::endl;
std::cout << "trim_left copy of str2 (space = '<>'): [" << boost::trim_left_copy_if(str2, boost::is_any_of("<>")) << "]" << std::endl;

std::cout << "trim_right copy of str1: [" << boost::trim_right_copy(str1) << "]" << std::endl;
std::cout << "trim_right copy of str2 (space = '<>'): [" << boost::trim_right_copy_if(str2, boost::is_any_of("<>")) << "]" << std::endl;

std::cout << "trimmed copy of str1: [" << boost::trim_copy(str1) << "]" << std::endl;
std::cout << "trimmed copy of str4 (space = '<>'): [" << boost::trim_copy_if(str2, boost::is_any_of("<>")) << "]" << std::endl;
std::cout << "trimmed copy of str5 (space = digit): [" << boost::trim_copy_if(str3, boost::is_digit()) << "]" << std::endl;

str1 = " 1x x x x1 ";
boost::trim_left(str1);
std::cout << "trim_left on str1: [" << str1 << "]" << std::endl;

str2 = "<>trim<>";
boost::trim_left_if(str2, boost::is_any_of("<>"));
std::cout << "trim_left of str2 (space = '<>'): [" << str2 << "]" << std::endl;

str1 = " 1x x x x1 ";
boost::trim_right(str1);
std::cout << "trim_right on str1: [" << str1 << "]" << std::endl;

str2 = "<>trim<>";
boost::trim_right_if(str2, boost::is_any_of("<>"));
std::cout << "trim_right of str2 (space = '<>'): [" << str2 << "]" << std::endl;

str1 = " 1x x x x1 ";
boost::trim(str1);
std::cout << "trim on str1: [" << str1 << "]" << std::endl;

str2 = "<>trim<>";
boost::trim_if(str2, boost::is_any_of("<>"));
std::cout << "trim of str2 (space = '<>'): [" << str2 << "]" << std::endl;

return 0;
}

find example

#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <boost/algorithm/string.hpp>

bool func(char c)
{
return c == 'o' || c == 'e' || c == 'l';
}

void findTokenExample()
{
char s1[] = "Hello and Welcome to Boost ";
char s2[] = "It is very interesting 7873";
char s3[] = "srtwyuzx 0043A";

boost::iterator_range<char*> it1 = boost::find_token(s1, func, boost::token_compress_on);
boost::iterator_range<char*> it2 = boost::find_token(s1, func);
boost::iterator_range<char*> it3 = boost::find_token(s2, boost::is_digit(), boost::token_compress_on);
boost::iterator_range<char*> it4 = boost::find_token(s2, boost::is_alpha(), boost::token_compress_on);
boost::iterator_range<char*> it5 = boost::find_token(s3, boost::is_xdigit(), boost::token_compress_on);

std::cout << "------------------------------------------------\n";
std::cout << "With token_compress_on in s1 : [" << it1 << "]" << std::endl;
std::cout << "Without token-compress_on in s1 : [" << it2 << "]" << std::endl << std::endl;
std::cout << "Identifying the first only digits token in s2 : [" << it3 << "]" << std::endl;
std::cout << "Identifying the first only alphabets token in s2 : [" << it4 << "]" << std::endl << std::endl;
std::cout << "Identifying the first hexadecimal token in s3: [" << it5 << "]" << std::endl;
}

int main()
{
std::cout << "* Find Example *" << std::endl << std::endl;

std::string str1("abc___cde__dfg");
std::string str2("abc");

boost::iterator_range<std::string::iterator> range = boost::find_first(str1, std::string("cde"));
boost::to_upper(range);
std::cout << "str1 with upper-cased part matching cde: " << str1 << std::endl;

char text[] = "hello dolly!";
boost::iterator_range<char*> crange = boost::find_last(text, "ll");
std::transform(crange.begin(), crange.end(), crange.begin(), std::bind2nd(std::plus<char>(), 1));
boost::to_upper(crange);
std::cout << text << std::endl;

std::string str3("this is an example of boost. It is useful. It is important.");
boost::iterator_range<std::string::iterator> second = boost::find_nth(str3, "is", 2);
boost::to_upper(second);
std::cout << str3 << std::endl;

boost::iterator_range<std::string::iterator> head = boost::find_head(str1, 3);
std::cout << "head(3) of the str1: " << std::string(head.begin(), head.end()) << std::endl;

head = boost::find_tail(str2, 5);
std::cout << "tail(5) of the str2: " << std::string(head.begin(), head.end()) << std::endl;

findTokenExample();

return 0;
}

predicate example

#include <string>
#include <iostream>
#include <functional>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/classification.hpp>

int main()
{
std::cout << "* Predicate Example *" << std::endl << std::endl;

std::string str1("123xxx321");
std::string str2("abc");

std::cout << std::boolalpha;
std::cout << R"(str1 starts with "123": )" << boost::starts_with(str1, std::string("123")) << std::endl;

std::cout << R"(str1 ends with "123": )" << boost::ends_with(str1, std::string("123")) << std::endl;

std::cout << R"(str1 contains "xxx": )" << boost::contains(str1, std::string("xxx")) << std::endl;

std::cout << R"(str2 equals "abc")" << boost::equal(str2, std::string("abc")) << std::endl;

std::cout << R"("abc" is lexicographically less than "abd": )" << boost::lexicographical_compare(std::string("abc"), std::string("abd")) << std::endl;

if (boost::all(";.,", boost::is_punct()))
{
std::cout << R"(";.," are all punctuation characters)" << std::endl;
}

if (boost::all("abcxxx", boost::is_any_of("xabc") && !boost::is_space()))
{
std::cout << true << std::endl;
}

return 0;
}