gpt4 book ai didi

c++ - xutility(2227) : warning C4996: 'std::_Copy_impl'

转载 作者:IT老高 更新时间:2023-10-28 23:18:05 24 4
gpt4 key购买 nike

我收到此警告消息.. 但我不知道问题出在哪里/哪里..!

包括

#pragma warning(push)
#pragma warning(disable:4996)
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#pragma warning(pop)

和警告

1>c:\program files (x86)\microsoft visual studio 10.0\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'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2212): Siehe Deklaration von 'std::_Copy_impl'
1> c:\users\perlig\documents\visual studio 2010\projects\restmanager\restmanager\**http.cpp(257)**: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_OutIt std::copy<boost::archive::iterators::insert_linebreaks<Base,N>,boost::archive::iterators::ostream_iterator<Elem>>(_InIt,_InIt,_OutIt)".
1> with
1> [
1> _OutIt=boost::archive::iterators::ostream_iterator<char>,
1> Base=boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<const char *,6,8>>,
1> N=76,
1> Elem=char,
1> _InIt=boost::archive::iterators::insert_linebreaks<boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<const char *,6,8>>,76>
1> ]

代码出现在第 257 行,如警告消息所述。但我无法修复它,因为我不知道出了什么问题..

字符串数据包含一个“用户:密码”字符串,用于通过 http 进行基本身份验证。

http.cpp(257):

// typdef, prepare
using namespace boost::archive::iterators;
stringstream os;
typedef
insert_linebreaks< // insert line breaks every 72 characters
base64_from_binary< // convert binary values ot base64 characters
transform_width< // retrieve 6 bit integers from a sequence of 8 bit bytes
const char *,
6,
8
>
>
,76
>
base64_text; // compose all the above operations in to a new iterator

// encrypt
#pragma warning(push)
#pragma warning(disable:4996)
copy( //<<<<<------ LINE 257
base64_text(data.c_str()),
base64_text(data.c_str() + data.size()),
boost::archive::iterators::ostream_iterator<char>(os)
);
#pragma warning(pop)

有人知道吗?

最佳答案

我想你知道警告的含义是什么,但首先我描述了警告,然后说如何摆脱它。 Microsoft 在其 CRT、STL、MFC 等中实现了一组新的启用安全功能的功能,并将这些功能的旧版本标记为已弃用,以提示您应该迁移到新的安全版本。所以它说 std::copy 不安全!如何?如下:

char storage[ 10 ], *p = storage;
std::copy( std::istream_iterator<int>(std::cin), std::istream_iterator<int>(), p );

现在如果用户输入超过 10 个 int 会发生什么?内存将被覆盖,您的内存被破坏了。

使用 boost::archive::iterators::ostream_iterator 是完全安全的,但由于它不遵循 MSVC 中安全迭代器的设计,因此将被视为不安全。

现在你应该通过 -D_SCL_SECURE_NO_WARNINGS 禁用这个警告到 cl 输入标志或添加一个 pragma 来禁用这个警告(就像你做的那样),但为什么 pragma 不起作用?

原因很明显,这个 pragma 在作用域上起作用,你在它上面使用 pragma 的作用域没有错,你必须用这个 pragma 保护 xutility,一切都会按预期工作。

关于c++ - xutility(2227) : warning C4996: 'std::_Copy_impl' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12270224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com