c++ - boost::trim_right_if 和空字符

标签 c++ boost

我有以下代码:

#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/

相关文章:

c++ - (低级C++)在一段数据上使用 "cout"时,它在显示在屏幕上之前是什么?

c++ - 使用 MinGW 构建 boost 给出 "argument error"

boost - 找到 map 中显示的 vector 元素

c++ - 从异构模板值的容器中返回模板类型

c++ - 为什么重载决策不选择我的模板函数的 std::vector 重载?

C++ 函数返回/输入引用类型

c++ - 继承静态变量成员,但分别共享给每一种继承类

c++ - pcl::PCLPointCloud2 用法

c++ - 将 boost 变体的 vector 过滤成新的 vector ?

c++ - boost.python 中没有