STL VS13 C++:错误 C4996 未禁用
STL VS13 C++: Error C4996 not disabling
我在 VS13 中有这段代码:
double distance(vector <double> point) {
return sqrt(inner_product(point[0], point[4], point, 0));
}
int main() {
vector < double > point {2, 2, 2, 2};
cout << distance(point);
cin.get();
}
这会调用
error C4996 ('std::_Inner_product2': 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)
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2825: '_Iter': must be a class or namespace when followed by '::'
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2039: 'value_type' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2146: syntax error : missing ';' before identifier 'value_type'
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2602: 'std::iterator_traits<_InIt>::value_type' is not a member of a base class of 'std::iterator_traits<_InIt>'
我知道这里有很多类似的问题。我还阅读了 MSDN 上的文档。
因此,我尝试了下一个解决方案:
1) #define _SCL_SECURE_NO_WARNINGS
根据过去的评论,它似乎有效,但对我来说,它会导致一大堆错误,例如:
c:\program files\microsoft visual studio 12.0\vc\include\xutility(371): error C2825: '_Iter': must be a class or namespace when followed by '::'
2)
#pragma warning(disable:4996)
#pragma warning(default:4996)
造成同样的错误;
3) 项目属性 -> 配置属性 -> C/C++ -> 常规 -> SDL 检查 -> No.
只是行不通。
你能看一看并写下如何消除该错误吗?谢谢!
我想你的意思是下面的函数
double distance( const std::vector<double> &point )
{
return std::sqrt( std::inner_product( point.begin(), point.end(), point.begin(), 0.0 ) );
}
这是一个演示程序
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
double distance( const std::vector<double> &point )
{
return std::sqrt( std::inner_product( point.begin(), point.end(), point.begin(), 0.0 ) );
}
int main()
{
std::vector<double> point = { 2, 2, 2, 2 };
std::cout << distance( point ) << std::endl;
}
输出为
4
工具
选项
高级
那里有一个部分用于抑制警告。
如果我没记错的话 4820;4996;4710 是三个我总是压制。
我在 VS13 中有这段代码:
double distance(vector <double> point) {
return sqrt(inner_product(point[0], point[4], point, 0));
}
int main() {
vector < double > point {2, 2, 2, 2};
cout << distance(point);
cin.get();
}
这会调用
error C4996 ('std::_Inner_product2': 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)
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2825: '_Iter': must be a class or namespace when followed by '::'
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2039: 'value_type' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2146: syntax error : missing ';' before identifier 'value_type'
c:\program files\microsoft visual studio 12.0\vc\include\xutility(372): error C2602: 'std::iterator_traits<_InIt>::value_type' is not a member of a base class of 'std::iterator_traits<_InIt>'
我知道这里有很多类似的问题。我还阅读了 MSDN 上的文档。
因此,我尝试了下一个解决方案:
1) #define _SCL_SECURE_NO_WARNINGS
根据过去的评论,它似乎有效,但对我来说,它会导致一大堆错误,例如:
c:\program files\microsoft visual studio 12.0\vc\include\xutility(371): error C2825: '_Iter': must be a class or namespace when followed by '::'
2)
#pragma warning(disable:4996)
#pragma warning(default:4996)
造成同样的错误;
3) 项目属性 -> 配置属性 -> C/C++ -> 常规 -> SDL 检查 -> No.
只是行不通。
你能看一看并写下如何消除该错误吗?谢谢!
我想你的意思是下面的函数
double distance( const std::vector<double> &point )
{
return std::sqrt( std::inner_product( point.begin(), point.end(), point.begin(), 0.0 ) );
}
这是一个演示程序
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
double distance( const std::vector<double> &point )
{
return std::sqrt( std::inner_product( point.begin(), point.end(), point.begin(), 0.0 ) );
}
int main()
{
std::vector<double> point = { 2, 2, 2, 2 };
std::cout << distance( point ) << std::endl;
}
输出为
4
工具 选项 高级
那里有一个部分用于抑制警告。
如果我没记错的话 4820;4996;4710 是三个我总是压制。