提高::修剪性病每个字符串::矢量&lt;标准::字符串&GT; [英] boost::trim each string in std::vector<std::string>
问题描述
我目前被困找到正确的语法在一个std :: vector的微调每个字符串。
我试过
的std ::矢量&lt;标准::字符串&GT;伏;
的std :: for_each的(v.begin(),v.end(),&安培;提高::装饰);
这给了我以下错误消息在MSVC7.1。
错误C2784:'_Fn1的std :: for_each的(_Init,_init,_Fn1):不能推导出模板参数从T1'的std ::矢量&lt; _Ty> ::迭代器'与[_Ty =的std ::字符串]:见的std :: for_each的
声明
错误C2896:'_Fn1的std :: for_each的(_Init,_init,_Fn1):不能使用函数模板无效的boost ::算法::修剪(SequenceT&安培;,常量的std ::区域设置和放大器;)'作为函数参数:详见的boost ::算法::微调
声明
块引用>如果我明确给出模板参数修剪第二个参数不能由编译器可以发现,虽然在默认情况下它的设定。
的std :: for_each的(v.begin(),v.end(),&安培;提高::修剪&LT;标准::字符串&GT;);
错误C2198:无效(__cdecl *)(标准::字符串&安培;,常量的std ::区域设置和放大器;):通过呼叫参数太少指针到函数
块引用>我不知道如何正确的语法来调用每个元素装饰在
v
会是什么样子。解决方案您需要修剪(语言环境)的第二个参数绑定,以及:
的std ::矢量&lt;标准::字符串&GT;伏;
的std :: for_each的(v.begin(),v.end()
提高::绑定(安培;提高::修剪&LT;的std ::字符串&gt;中
_1,性病::区域设置()));I'm currently stuck finding the correct syntax for trimming each string in a std::vector.
I tried
std::vector<std::string> v; std::for_each(v.begin(), v.end(), &boost::trim);
which gave me the following error messages in 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,_InIt,_Fn1)' : cannot use function template 'void boost::algorithm::trim(SequenceT &,const std::locale &)' as a function argument : see declaration of 'boost::algorithm::trim'
If I explicitly give the template parameter trims second parameter can not be found by the compiler, though its set by default.
std::for_each(v.begin(), v.end(), &boost::trim<std::string>);
error C2198: 'void (__cdecl *)(std::string &,const std::locale &)' : too few arguments for call through pointer-to-function
I was wondering how the correct syntax to call trim for each element in
v
would look like.解决方案You need to bind as well the second parameter of trim (the locale):
std::vector<std::string> v; std::for_each(v.begin(), v.end(), boost::bind(&boost::trim<std::string>, _1, std::locale() ));
这篇关于提高::修剪性病每个字符串::矢量&lt;标准::字符串&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!