为什么调用boost :: split()会给出如此多的警告?
问题描述:
我需要一个函数来分割字符串上的一个dleimiter,并且我正在使用boost库来处理其他事情,所以我尝试使用boost :: split。它的工作原理,但它给了我一堆警告,我想知道为什么。为什么调用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.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'
c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2212) : see declaration of 'std::_Copy_impl'
c:\program files\boost\boost_1_49_0\boost\algorithm\string\detail\classification.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 files\boost\boost_1_49_0\boost\algorithm\string\classification.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:\users\administrator\documents\visual studio 2010\projects\cas testing\tests\tests.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放在预定义的宏中。
+0
谢谢。我只是想确保在禁用警告之前我没有做任何错事。只需在项目的命令行选项上添加-D_SCL_SECURE_NO_WARNINGS即可,但声明_SCL_SECURE_NO_WARNINGS作为宏也可以。 – 2012-03-11 17:33:37
[C++ Boost:这个警告的原因是什么?](http://stackoverflow.com/questions/1301277/c-boost-whats-the-cause-of-this-warning) – Bart 2012-03-11 07:22:13
它编译在ideone上没有任何警告:http://ideone.com/LnNJA – Nawaz 2012-03-11 07:22:36
@Nawaz它很可能在VS中工作得很好。他们只是有一些过分保护性的警告。请参阅我所链接的可能欺骗。 (Ps。不知道ideone支持Boost,很好) – Bart 2012-03-11 07:24:50