为什么调用boost::split()会发出这么多警告

Why does calling boost::split() give so many warnings?

本文关键字:警告 boost 调用 split 为什么      更新时间:2023-10-16

我需要一个在dleimiter上拆分字符串的函数,而且我正在使用boost库做其他事情,所以我尝试使用boost::split。它有效,但它给了我很多警告,我想知道为什么。

以下是在MSVC++10中生成警告的简化代码:

#include <tchar.h>
#include <iostream>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
int _tmain(int argc, _TCHAR* argv[])
{
    std::vector<std::string> split_vector;
    boost::split(split_vector, "string,to,split", boost::is_any_of(","));
    for(size_t i=0;i<split_vector.size();i++)  {
        std::cout << split_vector[i] << "n";
    }
}

大约有100行警告,我不知道如何在这里制作可折叠/可滚动的东西,但它们都像:

c:program files (x86)microsoft visual studio 10.0vcincludexutility(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'
c:program files (x86)microsoft visual studio 10.0vcincludexutility(2212) : see declaration of 'std::_Copy_impl'
c:program filesboostboost_1_49_0boostalgorithmstringdetailclassification.hpp(102) : see reference to function template instantiation '_OutIt std::copy<const char*,char*>(_InIt,_InIt,_OutIt)' being compiled
with
[
    _OutIt=char *,
    _InIt=const char *
]
c:program filesboostboost_1_49_0boostalgorithmstringclassification.hpp(206) : see reference to function template instantiation 'boost::algorithm::detail::is_any_ofF<CharT>::is_any_ofF<boost::iterator_range<IteratorT>>(const RangeT &)' being compiled
with
[
    CharT=char,
    IteratorT=const char *,
    RangeT=boost::iterator_range<const char *>
]
c:usersadministratordocumentsvisual studio 2010projectscas testingteststests.cpp(10) : see reference to function template instantiation 'boost::algorithm::detail::is_any_ofF<CharT> boost::algorithm::is_any_of<const char[2]>(RangeT (&))' being compiled
with
[
    CharT=char,
    RangeT=const char [2]
]

等等

有人知道发生了什么事吗?

警告的第一行告诉一切,包括为什么和如何避免,以及其他内容:若要禁用此警告,请使用-D_SCL_SECURE_NO_WARNINGS。因此,转到项目属性,将_SCL_SECURE_NO_WARNINGS放在预定义的宏中。