Visual Studio 2012中的strcpy()错误 [英] strcpy() error in Visual studio 2012
问题描述
所以我有这个代码:
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
...
char* b = new char [10];
strcpy(b, "1234567890");
错误:Microsoft Visual Studio 11.0 \ vc \ include \ string.h(110):请参见'strcpy'的声明
error: microsoft visual studio 11.0\vc\include\string.h(110) : see declaration of 'strcpy'
我该如何解决?
推荐答案
在MSDN上有对此的解释和解决方案:
There's an explanation and solution for this on MSDN:
由于存在以下事实,函数strcpy被认为是不安全的没有边界检查,并可能导致缓冲区溢出.
The function strcpy is considered unsafe due to the fact that there is no bounds checking and can lead to buffer overflow.
因此,如错误描述中所建议,您可以使用strcpy_s而不是strcpy:
Consequently, as it suggests in the error description, you can use strcpy_s instead of strcpy:
strcpy_s(char * strDestination,size_t numberOfElements,
const char * strSource);
strcpy_s( char *strDestination, size_t numberOfElements,
const char *strSource );
和:
要禁用弃用,请使用_CRT_SECURE_NO_WARNINGS.有关详细信息,请参见在线帮助.
To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
http://social.msdn.microsoft.com/Forums/da-DK/vcgeneral/thread/c7489eef-b391-4faa-bf77-b824e9e8f7d2
这篇关于Visual Studio 2012中的strcpy()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!