Hello,

I am not sure what the error means. I think it has to do with how I called the strncpy function. My error is:

.cpp(70) : warning C4996: 'strncpy' was declared deprecated

My code is the following:

// set the tool name
void Tools::setToolName( string toolNameString)
{
   // copy at most 20 characters for the tool name
    const char *toolNameValue = toolNameString.data();
    int length = int(toolNameString.size());
    length = ( length < 20 ? length : 19 );
    strncpy( toolName, toolNameValue, length);
    toolName[ length ] = '\0'; // append null character to lastName
}

Don't worry, it's not an error: it's a VC++ warning. Ignore it (in this case). See notes in MSDN help page on this function (click strncpy then press F1).

It means that strncpy is old and/or something better is around to use instead of it.

MS (and probably other compiler vendors) are revising the string function to ensure greater safety. With strcpy, strcat and their variations, it's very easy to try to stuff more into a string array than it can hold. Therein lies the opening that many malware authors have exploited.

You can update your code to use the secure versions (they have an "_s" suffix and pass a parameter that is the size of the destination array), or continue with the old tried and true versions, adding the following to your code to suppress the warnings.
~~~~~~~~
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE

Use these #define's to halt the many warnings given by
Visual C++ 2005/2008 for use of "unsafe" string functions.
Place them before your #include statements.

see the link below for a full list of the functions that have
secure variations available

http://msdn2.microsoft.com/en-us/library/ms235384(VS.80).aspx

commented: Good answer. +20

Of course the real answer would be to use another std::string which is totally safe, as opposed to some non-portable API which is only safe so long as the programmer knows what they're doing.

thank you - this worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.