c++ - How to split a string and keep the delimiters using boost::split? -


I have a string like this:

  std :: string input ("I # Is going to learn how to use # # # # # # # # Library #);  

I do this:

  Std :: vector  splitVector; boost :: split (splitVector, input, boost :: is_any_of ("#"));  

and it Found: (split vector)

  splitVector: "i" "" "how" "" boos "is going to learn" libraries "" // "// Strange, why do I have an empty string here? **  

but want something like this:

  splitVector: "I'm going to #" # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # या हो सकता है कि Is there another way in this boost library? And in me  split vector  

Why does the empty string get? Boost: Split because the internal implementation that doesn \ 'tensen the token from split_iterator to boost / algorithm / string / find_iterator.hpp .

However you can get it from boost :: tokenizer , as there is an option to place delimiter in it:

whenever a delimiter appears In the input sequence, the current token is over, and a new token is started. The delimiters in the drop_delimymes do not show up in the form of tokens in output, whereas in the kept_dilymes the delimiters appear as tokens.

#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Boost / tokenizer.hpp & gt; Int main () {// continuous token for illustration added std :: string text = "I'm going to #AM # to learn #### # boost # library # # to use; :: char_separator & lt; four & gt; Sep ("", "#"); // Encourage only the Differentials: Tokenizer & lt; boost :: char_separator & lt; char & gt; & gt; Token Text, sep); {std :: ct & gt; [" [Use] [#] [#] [#] [#] [to use] [ #] [Boost] [#] [Library] [/] * /

Comments