错误C4996:'std :: _ Copy_impl':禁用它是否安全?

时间:2015-05-27 00:22:44

标签: c++ visual-studio-2012 boost odeint

我正在使用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);
}

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

1 个答案:

答案 0 :(得分:1)

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