编译时使用的boost ::分裂警告 [英] Warning with boost::split when compiling

查看:259
本文介绍了编译时使用的boost ::分裂警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/9653155/why-does-calling-boostsplit-give-so-many-warnings\">Why确实调用boost:斯普利特()给这么多的警告

所以,这是我的code:

So, this is my code:

Account ParseString(string data){
    vector <string> fields;
    boost::split( fields, data, boost::is_any_of( "a,;" ));
    int limit = fields.size();
    for(int i = 0; i < limit; i++)
        cout << fields[i] << endl;
}

和这是我在尝试编译时:

and this is what I get when trying to compile:

d:\program files (x86)\visualstudio\vc\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

我的问题是,我做了什么错?我能做些什么,以prevent这些错误消息?

My question is, what have I done wrong? What can I do to prevent those error messages?

推荐答案

您有没有做错什么。 Visual Studio是过于谨慎。在调试模式,视觉工作室使用了一种叫检查的迭代器。指针也是迭代器,但检查机制不与他们合作。因此,当一个标准库算法称为的指针,这是的boost ::拆分做,它会发出这样的警告。

You haven't done anything wrong. Visual Studio is being overly cautious. In debug mode, visual studio uses something called "Checked Iterators". Pointers are also iterators, but the checking mechanism doesn't work with them. So when a standard library algorithm is called with pointers, which is something that boost::split does, it issues this warning.

您将与这显然安全code得到同样的警告:

You'll get the same warning with this obviously safe code:

int main()
{
    int x[10] = {};
    int y[10] = {};
    int *a = x, *b = y;
    std::copy(a, a+10, b);
}

禁用警告。这是初学者。这是在默认情况下,适合初学者的安全,因为如果它是默认关闭的,他们不知道如何打开它。

Disable the warning. It's for beginners. It's on by default for the safety of beginners, because if it was off by default, they wouldn't know how to turn it on.

这篇关于编译时使用的boost ::分裂警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆