char_sep_example_2.cpp 823 B

1234567891011121314151617181920212223242526272829
  1. // (c) Copyright Jeremy Siek 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Sample output:
  6. //
  7. // <> <> <Hello> <|> <world> <|> <> <|> <> <foo> <> <bar> <yow> <baz> <|> <>
  8. // char_sep_example_2.cpp
  9. #include <iostream>
  10. #include <boost/tokenizer.hpp>
  11. #include <string>
  12. int main()
  13. {
  14. std::string str = ";;Hello|world||-foo--bar;yow;baz|";
  15. typedef boost::tokenizer<boost::char_separator<char> >
  16. tokenizer;
  17. boost::char_separator<char> sep("-;", "|", boost::keep_empty_tokens);
  18. tokenizer tokens(str, sep);
  19. for (tokenizer::iterator tok_iter = tokens.begin();
  20. tok_iter != tokens.end(); ++tok_iter)
  21. std::cout << "<" << *tok_iter << "> ";
  22. std::cout << "\n";
  23. return EXIT_SUCCESS;
  24. }