Error messages.

Lisa Settevig 21 Reputation points
2021-07-20T00:29:18.933+00:00

I'm getting the following message 'StrType3\StrType3.cpp(19,5): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.' And with 'strcat'. I have the following includes in the program <string> & <cstring>. I've entered this program from a book - 'C++ Primer Plus, 6th edition.'

Thank you.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,133 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,735 questions
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 9,676 Reputation points Microsoft Vendor
    2021-07-20T03:03:21.51+00:00

    Hi,

    I suggest you could refer to the Doc: Compiler Warning (level 3) C4996

    To fix a C4996 issue, we usually recommend you change your code. Use the suggested functions and global variables instead. If you need to use the existing functions or variables for portability reasons, you can turn off the warning.

    According to the error message, I suggest you could try to use strcpy_s instead of strcpy.

    You could also try to turn off deprecation warnings for these functions in the CRT via define _CRT_SECURE_NO_WARNINGS.

    For more details I suggest you could refer to the link: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=msvc-160#unsafe-crt-library-functions

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. RLWA32 45,571 Reputation points
    2021-07-20T00:38:40.997+00:00

    Well, the error message gave you the solution. Insert #define _CRT_SECURE_NO_WARNINGS in your source file prior to including any header files.

    0 comments No comments

  2. Lisa Settevig 21 Reputation points
    2021-07-29T00:05:54.75+00:00

    Thanks for your help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.