FrozenHeart FrozenHeart - 1 month ago 9
C++ Question

boost::trim_right_if and null characters

I have the following code:

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/assign/list_of.hpp>

#include <string>
#include <vector>

int main()
std::vector<char> some_vec = boost::assign::list_of('1')('2')('3')('4')('5')('\0')('\0');
std::string str(some_vec.begin(), some_vec.end());
boost::trim_right_if(str, boost::is_any_of("\0"));

I think that in str should be "12345", but there's "12345\0\0". Why and how can I solve it?

Answer Source

I do not know this functions boost::is_any_of but the fact that its argument is a string literal it seems it considers "\0" as an empty set of characters (en empty string literal). So the algorithm trims nothing.

It is only my supposition.