[英]Using C++ strtk results in an xutility error C4996
So I'm working on a little project to get into C++, and part of that is reading and writing data to a file. 所以我正在开发一个小项目来进入C ++,其中一部分是读取和写入数据到文件。 I've chosen the simplest route I know of, which is turning the various attributes of the object into a string of integers.
我选择了我所知道的最简单的路径,即将对象的各种属性转换为整数字符串。 To be clear, I'm working with an object "Day" which has various attributes about my day (minutes slept, minutes exercised, etc.) I currently have the following snippet of code:
为了清楚起见,我正在使用一个对象“Day”,它具有关于我的一天的各种属性(分钟睡觉,分钟运动等等)。我目前有以下代码片段:
string Day::writeAsData()
{
// Writes the day as a condensed machine-readable format:
// {rawTime,busyMinutes,sleepMinutes,productivity,enjoyment,fatigue,weight,calories}
// e.g. {1444316982,645,360,7,4,5,180,0}
string dataString = "{"
+ to_string(rawTime) + ","
+ to_string(busyMinutes) + ","
+ to_string(sleepMinutes) + ","
+ to_string(productivity) + ","
+ to_string(enjoyment) + ","
+ to_string(fatigue) + ","
+ to_string(weight) + ","
+ to_string(calories)
+ "}";
return dataString;
}
to write the data in a clear machine-readable format. 以清晰的机器可读格式写入数据。 I'm working on a companion function to get the data out of a string and set the values of the Day object appropriately.
我正在使用一个伴侣函数来从字符串中获取数据并适当地设置Day对象的值。 I found the C++ String Toolkit Library , and I want to use its parse() function.
我找到了C ++ String Toolkit库 ,我想使用它的parse()函数。 However, adding
但是,添加
#include "strtk.hpp"
to my list of includes ends up throwing a wrench in the build. 我的包含列表最终在构建中抛出一把扳手。 Taking that line out, I get a clean and successful build.
走出这条路线,我得到了一个干净而成功的构建。 However, adding that line results in
但是,添加该行会导致
Error C4996 'std::_Fill_n': 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.
in line 2811 of xutility. 在xutility的第2811行。 I don't use std::Fill_n anywhere in my code.
我不在我的代码中的任何地方使用std :: Fill_n。
So far, I've found that the String Toolkit uses the Boost libraries, which I have placed in my include directory. 到目前为止,我发现String Toolkit使用了我在include目录中放置的Boost库。 I tried to add
我试着补充一下
#define D_SCL_SECURE_NO_WARNINGS 1
to my Day.cpp file and my Day.h file, but neither have done anything. 到我的Day.cpp文件和我的Day.h文件,但都没有做任何事情。 I can't add it to xutility because the file is read only.
我无法将其添加到xutility中,因为该文件是只读的。 How can I either disable the warning or fix the issue?
如何禁用警告或解决问题?
First, your #define is not correct, it should be: 首先,你的#define不正确,它应该是:
#define _SCL_SECURE_NO_WARNINGS
More details here: MSDN: _SCL_SECURE_NO_WARNINGS 更多细节: MSDN:_SCL_SECURE_NO_WARNINGS
And here: What does "use -D_SCL_SECURE_NO_WARNINGS" mean? 在这里: “使用-D_SCL_SECURE_NO_WARNINGS”是什么意思?
Second, if you are using visual studio (and I assume you are) you can define _SCL_SECURE_NO_WARNINGS for your whole project using the project settings under Preprocessor Definitions 其次,如果您正在使用visual studio(我假设您是),您可以使用预处理器定义下的项目设置为整个项目定义_SCL_SECURE_NO_WARNINGS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.