错误 C4996:"std::_Copy_impl":禁用它是否安全?

error C4996: 'std::_Copy_impl': is it safe to disable it?

本文关键字:是否 安全 Copy C4996 std 错误 impl      更新时间:2023-10-16

我使用odeint boost来求解微分方程。在visual studio 2010中,没有错误显示,但当我使用visual studio 2013时,我得到这个错误

xutility(2132): error 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'

我已经通过使用这个#pragma warning( disable : 4996 )禁用警告解决了这个问题,odeint中提供的示例现在正在工作。这是示例,

#pragma warning( disable : 4996 )
#include <iostream>
#include <boost/array.hpp>
#include <boost/numeric/odeint.hpp>
using namespace std;
using namespace boost::numeric::odeint;
const double sigma = 10.0;
const double R = 28.0;
const double b = 8.0 / 3.0;
typedef boost::array< double, 3 > state_type;
void lorenz(const state_type &x, state_type &dxdt, double t)
{
    dxdt[0] = sigma * (x[1] - x[0]);
    dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
    dxdt[2] = -b * x[2] + x[0] * x[1];
}
void write_lorenz(const state_type &x, const double t)
{
    cout << t << 't' << x[0] << 't' << x[1] << 't' << x[2] << endl;
}
int main(int argc, char **argv)
{
    state_type x = { 10.0, 1.0, 1.0 }; // initial conditions
    integrate(lorenz, x, 0.0, 25.0, 0.1, write_lorenz);
}

我的问题是禁用此警告是否安全?由于

代码应该是安全的。我们在odeint的单元测试中禁用了相同的警告。