Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C++ strtk results in an xutility error C4996

Tags:

c++

string

So I'm working on a little project to get into C++, and part of that is reading and writing data to a file. 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:

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. I found the C++ String Toolkit Library, and I want to use its parse() function. 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. I don't use std::Fill_n anywhere in my code.

So far, I've found that the String Toolkit uses the Boost libraries, which I have placed in my include directory. 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. I can't add it to xutility because the file is read only. How can I either disable the warning or fix the issue?

like image 437
James Boggs Avatar asked Dec 11 '15 19:12

James Boggs


1 Answers

First, your #define is not correct, it should be:

#define _SCL_SECURE_NO_WARNINGS

More details here: MSDN: _SCL_SECURE_NO_WARNINGS

And here: What does "use -D_SCL_SECURE_NO_WARNINGS" mean?

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

like image 52
yms Avatar answered Nov 16 '22 15:11

yms