boost::trim std::vector中的每个字符串
我目前一直在寻找修剪 std::vector 中每个字符串的正确语法。
我尝试
std::vector<std::string> v;
std::for_each(v.begin(), v.end(), &boost::trim);
在 MSVC7.1 中给出以下错误消息。
错误 C2784: '_Fn1 std::for_each(_InIt,_InIt,_Fn1)' : 无法使用 [_Ty=std:: 从 'std::vector<_Ty>::iterator' 推导出 'T1' 的模板参数string] :参见 'std::for_each' 的声明
错误 C2896: '_Fn1 std::for_each(_InIt,_InIt,_Fn1)' : 无法使用函数模板 'void boost::algorithm::trim(SequenceT &,const std::locale &)' 作为函数参数:参见“boost::algorithm::trim”的声明
如果我显式给出模板参数 TRIM,则编译器无法找到第二个参数,尽管它是默认设置的。
std::for_each(v.begin(), v.end(), &boost::trim<std::string>);
错误 C2198:“void (__cdecl *)(std::string &,const std::locale &)”:通过函数指针调用的参数太少
我想知道如何为每个调用修剪的正确语法v
中的元素看起来像。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还需要绑定trim的第二个参数(区域设置):
You need to bind as well the second parameter of trim (the locale):