微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – xutility(2227):warning C4996:’std :: _ Copy_impl’

我得到这个警告信息..但我不知道什么/在哪里的问题是..

包括

#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 *,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 *,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,每件事情都将按预期工作.

原文地址:https://www.jb51.cc/c/114002.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐