replace去除空格

旧街凉风 提交于 2019-12-04 12:04:10

执行redis 命令的时候会默认用 空格  分割命令,所以当value 中存在空格,就会导致命令执行错误。于是,我想到了用replace函数去除空格,发现了几个注意事项:

  1. 单引号里面必须有值,替换空字符用'\0',也可以达到移除的效果
  2. replace函数是直接修改入参的!所以必须保证入参不是常量

/usr/include/c++/4.8.2/bits/stl_algo.h: In instantiation of ‘void std::replace(_FIter, _FIter, const _Tp&, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >; _Tp = char]’:
OrderPool.cpp:226:85: required from here
/usr/include/c++/4.8.2/bits/stl_algo.h:4998:13: error: assignment of read-only location ‘__first.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<const char*, std::basic_string<char> >()’
*__first = __new_value;

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!