Using boost::tokenizer with string delimiters

前端 未结 4 1545
南笙
南笙 2020-12-31 11:34

I\'ve been looking boost::tokenizer, and I\'ve found that the documentation is very thin. Is it possible to make it tokenize a string such as \"dolphin--monkey--baboon\" and

4条回答
  •  Happy的楠姐
    2020-12-31 12:24

    using iter_split allows you to use multiple character tokens. The code below would produce the following:

    dolphin
    mon-key
    baboon

    #include 
    #include 
    #include 
    #include 
    
        // code starts here
        std::string s = "dolphin--mon-key--baboon";
        std::list stringList;
        boost::iter_split(stringList, s, boost::first_finder("--"));
    
        BOOST_FOREACH(std::string token, stringList)
        {    
            std::cout << token << '\n';  ;
        }
    

提交回复
热议问题