12

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?

James Boggs
  • 121
  • 3

1 Answers1

10

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

Community
  • 1
  • 1
yms
  • 10,361
  • 3
  • 38
  • 68
  • So this worked, sort of. I defined it in the Preprocessor Settings, and the error stopped showing up. Now, though, it is giving me error LNK1104: cannot open file 'libboost_regex-vc140-mt-gd-1_59.lib' – James Boggs Dec 11 '15 at 22:19
  • see if this helps: http://stackoverflow.com/questions/2274188/fatal-error-lnk1104-cannot-open-file-libboost-regex-vc90-mt-gd-1-42-lib – yms Dec 12 '15 at 00:45
  • By default strtk uses boost. There are preprocessor directives that control the inclusion of boost. You can turn the use of boost off and will not have the error. Look for #ifndef strtk_no_tr1_or_boost in the header. – DannyK Mar 11 '20 at 20:22
  • @DannyK I am not sure that is the case for Visual Studio on Windows. At least it was not the case when this answer was written. – yms Mar 25 '20 at 22:20