Wednesday, June 30, 2010

boost::tokenizer

A simple example how to use boost::tokenizer.

This splits a string by a space (' ').

std::string dummy = "abcd efg hijk lmn opqr stu vw xyz";

typedef boost::tokenizer< boost::char_separator< char > > tokenizer;
boost::char_separator< char > sep(" ");
tokenizer tok( dummy, sep );

std::vector< std::string > > vTokes;
std::copy( tok.begin(), tok.end(), std::back_inserter( vTokes ) );
For my small brain capacity.

No comments:

Post a Comment