boost::trim std::vector中的每个字符串

发布于 2024-08-20 19:53:21 字数 867 浏览 6 评论 0原文

我目前一直在寻找修剪 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹沉浮 2024-08-27 19:53:21

您还需要绑定trim的第二个参数(区域设置):

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

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() ));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文