1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <string>
#include <boost/tokenizer.hpp>
#include <iostream>
int main()
{
std::string str = "ab, c, ++++2++++, defg, hi, jkmn, o, p, qrs, tu, v, ----2----, wx, yz" ;
boost::char_separator<char> fn( ", \t" ) ;
// get the token two places from begining
boost::tokenizer< boost::char_separator<char> > toker( str, fn) ;
auto iter = toker.begin() ;
std::cout << *++++iter << '\n' ; // ++++2++++
// get the token two places before the end
boost::tokenizer< boost::char_separator<char>,
std::string::const_reverse_iterator > rev_toker( str.rbegin(), str.rend(), fn ) ;
auto rev_iter = rev_toker.begin() ;
std::cout << *++++rev_iter << '\n' ; // ----2----
}
|