编译时使用升压警告::分裂[复制](Warning with boost::split when c

2019-08-05 10:50发布

可能重复:
为什么调用boost:斯普利特()给这么多的警告?

所以,这是我的代码:

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;
}

这就是我得到在编译的时候:

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'

我的问题是,我做了什么错? 我能做些什么来防止这些错误消息?

Answer 1:

你没有做错任何事。 Visual Studio是过于谨慎。 在调试模式下,Visual Studio中使用一种叫“检查的迭代器”。 指针也是迭代器,但检查机制不与他们合作。 所以,当一个标准库算法称为在指针上,这是什么boost::split呢,它会发出这样的警告。

你会得到与此明显安全的代码相同的警告:

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

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



Answer 2:

你没有做错任何事,如果你在警告看看它似乎并没有那么可怕:)另外,我相信在这种情况下,你是不是需要执行的,一个任何行动。



文章来源: Warning with boost::split when compiling [duplicate]