Error c4996 Checked Iterators

我只是一个虾纸丫 提交于 2020-01-14 01:54:34

问题


I use VC++ 2013 and I have a following code:

#pragma warning(disable:4996)
#define D_SCL_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <object.pb.h>

using namespace std;

int main(int argc, char** argv)
{
    Object object;
    object.set_id(1);
    object.set_name("Ermolaev Ivan");
    object.set_vertex(300.0f);
    fstream output("myfile", ios::out | ios::binary);
    object.SerializeToOstream(&output);
    return 0x0;
}

But following error continue displayed.

Error   1   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'   c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 2132    1   ProtobufTest

回答1:


The D prefix is not necessary, it's an indicator for the compiler when you introduce the define on the command line.

You should define this as simply _SCL_SECURE_NO_WARNINGS. It's best to do this in Project Properties -> C++ -> Preprocessor, to have it consistent across all your code.




回答2:


if you using selfmaden iterators then typedef iterator _Unchecked_type; inside of custom iterator, make microsoft std library trust it is checket.

class iterator: public std::iterator<std::input_iterator_tag, const uint8_t>
{
public:

    typedef iterator _Unchecked_type;
// your implementation here
}


来源:https://stackoverflow.com/questions/21655496/error-c4996-checked-iterators

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!