我有以下代码:
#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"));
}
我认为str中应该是“12345”,但是有“12345\0\0”。为什么以及如何解决它?
最佳答案
此代码有效
boost::trim_right_if(str, boost::is_any_of(boost::as_array("\0") );
诀窍是使用boost::as_array
关于c++ - boost::trim_right_if 和空字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20685086/