strcpy() error in Visual studio 2012

2020-05-29 00:29发布

so I have this code:

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

...

char* b = new char [10];
strcpy(b, "1234567890");

error: microsoft visual studio 11.0\vc\include\string.h(110) : see declaration of 'strcpy'

How do I fix it?

7条回答
乱世女痞
2楼-- · 2020-05-29 00:54

A quick fix is to add the _CRT_SECURE_NO_WARNINGS definition to your project's settings

Right-click your C++ and chose the "Properties" item to get to the properties window.

Now follow and expand to, "Configuration Properties"->"C/C++"->"Preprocessor"->"Preprocessor definitions".

In the "Preprocessor definitions" add

_CRT_SECURE_NO_WARNINGS

but it would be a good idea to add

_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)

as to inherit predefined definitions

IMHO & for the most part this is a good approach.

查看更多
登录 后发表回答