我正在使用boost::lambda删除字符串中随后的空白,只留下一个空格。我试过这个程序。
#include <algorithm>
#include <iostream>
#include <string>
#include <boost/lambda/lambda.hpp>
int main()
{
std::string s = "str str st st sss";
//s.erase( std::unique(s.begin(), s.end(), (boost::lambda::_1 == ' ') && (boost::lambda::_2== ' ')), s.end()); ///< works
s.erase( std::unique(s.begin(), s.end(), (boost::lambda::_1 == boost::lambda::_2== ' ')), s.end()); ///< does not work
std::cout << s << std::endl;
return 0;
}
注释行可以正常工作,但未注释行不行。
如何
(boost::lambda::_1 == boost::lambda::_2== ' ')
不同于
(boost::lambda::_1 == ' ') && (boost::lambda::_2== ' '))
在上面的程序中。注释的一个还警告我“warning c4805:'=':操作中类型'bool'和类型'const char'的不安全混合”
谢谢。