簡體   English   中英

錯誤c4996已檢查的迭代器

[英]Error c4996 Checked Iterators

我使用VC ++ 2013,我有以下代碼:

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

但繼續顯示以下錯誤。

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

如果你使用selfmaden迭代器然后typedef iterator _Unchecked_type; 在自定義迭代器內部,使microsoft std庫信任它是checket。

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

    typedef iterator _Unchecked_type;
// your implementation here
}

D前綴不是必需的,它是在命令行中引入define時編譯器的指示器。

您應該將其定義為_SCL_SECURE_NO_WARNINGS 最好在Project Properties -> C++ -> Preprocessor執行此操作,以使其在所有代碼中保持一致。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM