C++使用函数strcpy出现bug: 错误 C4996 'strcpy': This function or variable
C++中使用函数strcpy时出现问题:

解决方案:
在文件开头添加语句:
#pragma warning(disable:4996)
done!
剑指offer:
第一题:赋值运算符函数
#include "stdafx.h"
#include<iostream>
#include<string>
#pragma warning(disable:4996) //debug using std::cout;
using std::endl; class mystring
{
public:
mystring(char* data = nullptr);
mystring(const mystring & str);
~mystring();
mystring & operator=(const mystring & s);
void print();
private:
char* m_data;
}; mystring::mystring(char* data)
{
if (data == nullptr)
{
data = new char[];
data[] = '\0'; }
else
{
int length = strlen(data);
m_data = new char[(length + )];
strcpy(m_data, data); }
} mystring::mystring(const mystring & s)
{
int length = strlen(s.m_data);
m_data = new char[(length + )];
strcpy(m_data, s.m_data); } mystring::~mystring()
{
delete[]m_data;
} mystring & mystring::operator=(const mystring & s)
{
if (this == &s)
return *this; delete[]m_data;
m_data = nullptr; m_data = new char[strlen(s.m_data) + ];
strcpy(m_data, s.m_data); } void mystring::print()
{
cout<<("s%", m_data)<<endl; } int main() {
mystring kk = "hello";
mystring nn;
nn = kk;
kk.print();
nn.print();
system("pause");
return ;
}
C++使用函数strcpy出现bug: 错误 C4996 'strcpy': This function or variable的更多相关文章
- Visual Studio 2015 编译错误【错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s instead. 】的解决方案
错误提示信息: 错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s inst ...
- vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案
编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...
- 严重性代码说明项目文件行错误C4996'strcpy' 和Unicode 字符集选择问题
严重性代码说明项目文件 行错误 C4996 ‘strcpy’: This function or variable may be unsafe. Consider using strcpy_s ins ...
- vs2013/2015中scanf函数类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
在使用vs2015时,遇到了scnaf函数安全性的问题,程序不能正常运行,错误如下: error C4996: 'scanf': This function or variable may be un ...
- VS 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
在VS中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may be uns ...
- Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
在VS 2012 中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may ...
- 解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
用习惯了VS老版本的人当刚使用VS2013的时候可能总遇到类似于这样的错误: error C4996: 'scanf': This function or variable may be unsafe ...
- [转]Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
原文地址:http://www.cnblogs.com/gb2013/archive/2013/03/05/SecurityEnhancementsInTheCRT.html 在VS 2012 中编译 ...
- error C4996: 'fopen': This function or variable may be unsafe.
vs2013中错误提示信息: error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s ...
随机推荐
- Linux学习-DNS服务相关
一.DNS服务简介 1.基本概念 (1) DNS( Domain Name System )域名系统,是一种组织成域层次结构的计算机和网络服务命名系统,是一个应用层协议,使用TCP与UDP的53端口, ...
- CSS基础知识总结之css样式引用的三种方式
在html中增加css样式有三种: 1.在标签中增加style属性: <!DOCTYPE html> <html lang="en" xmlns="ht ...
- vue中的render函数介绍
简介:对于不了解slot的用法(参考:大白话vue-slot的用法)又刚接触render函数的同学来说,官网的解释无疑一脸懵逼,这里就整理下个人对render函数的理解 问题: 1.render函数是 ...
- 牛客多校第五场G
subsequence 1 只要处理长度等于t的. 转移方程没想出来QAQ $dp(i,j,0)$代表到$s[i]$为止有多少个前缀序列与$t[0\cdots j]$相同 所以有$dp(i,j,0)= ...
- String reduction (poj 3401
String reduction Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1360 Accepted: 447 D ...
- weilaiqiche
<!DOCTYPE html><html lang="en"> <head> <meta http-equiv="Content ...
- Windows 下开启FTP服务并创建FTP用户
Windows 下开启FTP服务,并创建用户 此教程教你怎么开启 Windows 的 FTP 服务,并创建用于登入 FTP 的用户.教程用到的操作系统是 Windows 7. 一.创建用于登入 FTP ...
- mysql_DML_select_聚合join
聚合函数: select avg(salary)//平均值 from wsb; select sum(salary)//总和 from wsb; select max(salary)//最大 from ...
- applicationContext.xml无错有红叉,Error occured processing XML 'Provider org.apache.xerces.parsers.解决方案
applicationContext.xml无错有红叉,网上讲的取消xml验证的方法没用... 甚至我的myeclipse10连windows-->perferences-->myecli ...
- quick BI 修改列名备注
有些列名太长了,所以造成些影响.注意修改即可.