加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – boost ::修剪std :: vector中的每个字符串

发布时间:2020-12-16 03:19:07 所属栏目:百科 来源:网络整理
导读:我目前正在找到正确的语法来修剪std :: vector中的每个字符串. 我试过了 std::vectorstd::string v;std::for_each(v.begin(),v.end(),boost::trim); 这在MSVC7.1中给了我以下错误消息. error C2784: ‘_Fn1 std::for_each(_InIt,_InIt,_Fn1)’ : could not d
我目前正在找到正确的语法来修剪std :: vector中的每个字符串.

我试过了

std::vector<std::string> v;
std::for_each(v.begin(),v.end(),&boost::trim);

这在MSVC7.1中给了我以下错误消息.

error C2784: ‘_Fn1 std::for_each(_InIt,_InIt,_Fn1)’ : could not deduce template argument for ‘T1’ from ‘std::vector<_Ty>::iterator’ with [_Ty=std::string] : see declaration of ‘std::for_each’

error C2896: ‘_Fn1 std::for_each(_InIt,_Fn1)’ : cannot use function template ‘void boost::algorithm::trim(SequenceT &,const std::locale &)’ as a function argument : see declaration of ‘boost::algorithm::trim’

如果我明确地给模板参数修剪第二个参数,编译器无法找到,尽管它默认设置.

std::for_each(v.begin(),&boost::trim<std::string>);

error C2198: ‘void (__cdecl *)(std::string &,const std::locale &)’ : too few arguments for call through pointer-to-function

我想知道如何使用正确的语法调用v中每个元素的修剪.

解决方法

您还需要绑定trim(语言环境)的第二个参数:
std::vector<std::string> v;
std::for_each(v.begin(),boost::bind(&boost::trim<std::string>,_1,std::locale() ));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读