-1

im starting to learn C++ (just finished with C) and Im trying to use strings. Ive included the library, and i get this error when compiling:

    Severity    Code    Description Project File    Line    Suppression State
Error   C4996   'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

Now I know that this is due to the risk in buffer overflow, but in my task I have to do it that way. I've read that adding the #define _CRT_SECURE_NO_WARNINGS is suppose to remove that warning, but it doesnt...

Ðаn
  • 10,934
  • 11
  • 59
  • 95
  • 1
    I would recommend using `strncpy` over `strcpy`. It allows you specify the maximum length of characters to copy in to the buffer and avoid writing over the end of buffer and receiving a buffer overflow. `strncpy(char* destination, char* source, size_t num)`. Or, if you're sticking with windows development, `strcpy_s` as suggested in the error. – Ingenioushax Mar 23 '17 at 16:14

2 Answers2

0

In your project setting, C/C++ -> Command Line, add following:

/D_CRT_SECURE_NO_WARNINGS 

This will remove the warning.

zhm
  • 3,513
  • 3
  • 34
  • 55
-1

Use _CRT_SECURE_NO_WARNINGS in C/C++ -> Preprocessor -> Preprcessor Definitions.

TuneFanta
  • 157
  • 2
  • 10