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 ...
随机推荐
- 奇异值分解(SVD)(基础知识)
参考:https://www.cnblogs.com/pinard/p/6251584.html 参考:http://blog.csdn.net/u010099080/article/details/ ...
- Java泛型与集合笔记
第一章 Java的泛型为了兼容性和防止代码爆炸,在编译成字节碼时会进行类型擦除,编译器自动添加代码做类型转换(用到List<Integer>的地方用Integer来做转换),自动做装箱拆箱 ...
- python学习笔记(十三)处理时间模块
import time time.sleep(2)#等待几秒 时间的三种表现方式: 1.格式化好的时间 2018-1-14 16:12 2.时间戳 是从unix元年到现在所有的秒数 3.时间元组 想时 ...
- 5G即将到来,你还会购买4G手机吗?
科技在不断进步,通信技术也是如此,5G网络将于明年下半年开始测试部署,4G手机是否值得更换呢?三星上周发布了Galaxy Note 9智能手机,这也给消费者带来了一个难题:到底是现在花上1000美元将 ...
- 观察者模式使用WebForm实现的例子
观察者模式是一种可以描述一对多对象依赖关系的行为模式.当一个对象状态发生变化时,依赖它的其它对象会自动被更新状态.下面这个图展示了观察者模式的层级: 举个例子吧,我们某个报表界面现在有个dashboa ...
- SQL中MINUS的用法与UNION的用法
一:MINUS指令 其是运用在两个 SQL 语句上.它先找出第一个 SQL 语句所产生的结果,然后看这些结果有没有在第二个 SQL语句的结果中.如果有的话,那第一个SQL结果数据就被去除,而不会在最后 ...
- Unregistering JMX-exposed beans on shutdown解决方法:
Unregistering JMX-exposed beans on shutdown解决方法: 加入依赖如下: <dependency> <groupId>org.spr ...
- JavaScript原型和闭包学习笔记
在这里先和大家推荐一个博客,这博客的<深入理解javascript原型和闭包(完结)>系列,看了比较多的视频和书本,这个博客讲得很耐人寻味. 深入理解javascript原型和闭包(完结) ...
- 在google chrome浏览器上安装 Vue Devtools工具
[转]https://www.cnblogs.com/tanyongli/p/7554045.html Vue.js devtools是基于google chrome浏览器的一款调试vue.js应用的 ...
- vue鼠标修饰符
鼠标左键事件 <div @click.left="mouseClick" style="border: solid 1px red; width:500px; he ...