Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem in solving "C4996" error

problem in solving "C4996" error

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studio
5 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Sir, I need to create "string" as an output using my formatted data. To achieve this I did make use of "sprintf" function.But when building a solution using visual studio I get "C4996" error. Here is the error message which I get:

    Quote:

    Severity Code Description Project File Line Error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 155

    to disable all depreciation I've used this preprocessors as per my compiler's suggestion

    #define _CRT_SECURE_NO_DEPRECATE
    #define _CRT_SECURE_NO_WARNINGS

    :confused: but still the error persists.I have also decreased the warning level. Kindly help me.

    J L 2 Replies Last reply
    0
    • L Lost User

      Sir, I need to create "string" as an output using my formatted data. To achieve this I did make use of "sprintf" function.But when building a solution using visual studio I get "C4996" error. Here is the error message which I get:

      Quote:

      Severity Code Description Project File Line Error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 155

      to disable all depreciation I've used this preprocessors as per my compiler's suggestion

      #define _CRT_SECURE_NO_DEPRECATE
      #define _CRT_SECURE_NO_WARNINGS

      :confused: but still the error persists.I have also decreased the warning level. Kindly help me.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      _CRT_SECURE_NO_WARNINGS must be defined before the header files that use the macro are included. So put it on top of your source file before including any header files. To set it for all files of a project, add it on top of stdafx.h (when using that) or add it to the preprocessor definitions of your project settings (Configuration Properties - C++ - Preprocessor - Preprocessor Definitions). Decreasing the warning level does not help here because the warning is treated as an error. To treat them as warnings, set SDL Checks to No in your project settings (Configuration Properties - C++ - General). Another option is disabling the warning by using a pragma statement:

      #pragma warning(disable : 4996)

      This is useful when using those deprecated functions only a few times because they can be disabled on function level:

      #pragma warning(disable : 4996)
      void SomeFunc()
      {
      // Uses deprecated functions here
      }
      #pragma warning(enable : 4996)

      L 1 Reply Last reply
      0
      • L Lost User

        Sir, I need to create "string" as an output using my formatted data. To achieve this I did make use of "sprintf" function.But when building a solution using visual studio I get "C4996" error. Here is the error message which I get:

        Quote:

        Severity Code Description Project File Line Error C4996 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 155

        to disable all depreciation I've used this preprocessors as per my compiler's suggestion

        #define _CRT_SECURE_NO_DEPRECATE
        #define _CRT_SECURE_NO_WARNINGS

        :confused: but still the error persists.I have also decreased the warning level. Kindly help me.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        A better solution would be to do what the message says and use the sprintf_s function to create formatted strings. Or even to use the STL libraries if this is C++.

        L 1 Reply Last reply
        0
        • J Jochen Arndt

          _CRT_SECURE_NO_WARNINGS must be defined before the header files that use the macro are included. So put it on top of your source file before including any header files. To set it for all files of a project, add it on top of stdafx.h (when using that) or add it to the preprocessor definitions of your project settings (Configuration Properties - C++ - Preprocessor - Preprocessor Definitions). Decreasing the warning level does not help here because the warning is treated as an error. To treat them as warnings, set SDL Checks to No in your project settings (Configuration Properties - C++ - General). Another option is disabling the warning by using a pragma statement:

          #pragma warning(disable : 4996)

          This is useful when using those deprecated functions only a few times because they can be disabled on function level:

          #pragma warning(disable : 4996)
          void SomeFunc()
          {
          // Uses deprecated functions here
          }
          #pragma warning(enable : 4996)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Thank you Sir for your kind help.It works after defining "_CRT_SECURE_NO_WARNINGS " before the header files.

          1 Reply Last reply
          0
          • L Lost User

            A better solution would be to do what the message says and use the sprintf_s function to create formatted strings. Or even to use the STL libraries if this is C++.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Thank you Sir for your kind help.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups