首先,它任然是有效的C++代码,应为你写的char* 是具有c风格的字符串,所以g++不识别

可以选择在编译的时候加上:g++ -Wno-write-strings text.cpp //忽略警告。。。

其实这样是并不是很安全

上代码

1 #include <iostream>2 #include <stdio.h>3 #include <string.h>4 using namespace std;5 6 class Student{7   private:8     int score;9     char *name;//可变的变量10   public:11     Student(const char *name,int score);12     Student(Student& stu);13     ~Student();14     void  show();15 };16 17 Student::Student(const char *name1,int score1)//这里改了const18 {19   cout<<"constructing ..."<<endl;20 21   name = new char[strlen(name1)+1];22   if(name != 0)23   {24     strcpy(name,name1);25     score = score1;26   }27 }28 29 Student::~Student()30 {31   cout<<"Destructing..."<<endl;32   name[0] = '\0';33   delete name;34 }35 36 Student::Student(Student& stu)37 {38   cout<<"copy constructing ..."<<endl;39   name = new char[strlen(stu.name)+1];40   if(name != 0)41   {42     strcpy(name,stu.name);43 44     score=stu.score;45   }46 }47 48 void Student::show()49 {50   cout<<name<<endl;51   cout<<score<<endl;52 }53 54 int main()55 {56   Student stu1("huhao",101);//在这里传入的是const的变量57   /*58   Student stu2=stu1;59   stu1.show();60   stu2.show();*/61 }

c++:warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]相关推荐

  1. deprecated conversion from string constant to ‘char*’

    deprecated conversion from string constant to 'char*' #include <iostream> using namespace std; ...

  2. warning:deprecated conversion from string constant to 'char *' 解决方案

    #include <iostream> using namespace std; int fuc(char *a) {     cout << a << endl; ...

  3. C++: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

    不允许将字符串常量,给char指针. warning.c: In function 'int main()': warning.c:9:19: warning: ISO C++ forbids con ...

  4. C++11编译问题:warning: ISO C++11 does not allow conversion from string literal to ‘char *‘

    在新写的采用C++11标准的编译器里,进行编译以后,原来没有任何提示的语句,竟然出现如下问题: char* a="abc"; std::cout << a <&l ...

  5. linux c++ 警告 warning: ISO C++ forbids converting a string constant to ‘char*‘ [-Wwrite-strings] 解决方法

    在C++中, char* p = "abc"; // valid in C, invalid in C++ 会跳出警告:warning: ISO C++ forbids conve ...

  6. warning: ISO C++ forbids converting a string constant to ‘char*‘ [-Wwrite-strings]

    warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 在C++11中有明确规定 char ...

  7. arm linux c++编译警告:ISO C++ forbids converting a string constant to ‘char*’(需要把const char*转换成char*)

    编译时遇到警告: /home/yg/rv/sdk/rv1.8/rv1126_rv1109/buildroot/output/rockchip_rv1126_rv1109/build/ky_ai_cam ...

  8. linux c++ 警告: ISO C++ forbids converting a string constant to char*

    在C++11中有明确规定 char* p = "abc"; // valid in C, invalid in C++ 如果你进行了这样的赋值,那么编译器就会跳出诸如标题的警告.但 ...

  9. 「 C/C++疑难杂症 」warning: ISO C++ forbids converting a string constant to ‘CHAR*’ {aka ‘char*’} [-Wwrite

    文章目录

  10. Warning: Missing charsets in String to FontSet conversion

    当出现Warning: Missing charsets in String to FontSet conversion时 输入export LANG=C即可解决

最新文章

  1. 运行在浏览器中的深度学习框架,开源了
  2. 【Linux】28_网站服务动态站点
  3. [Python]从零开始学python——Day03 字典,元组
  4. CPU的高速缓存存储器知识整理
  5. [css] css的linear-gradient有什么作用呢?
  6. System.load(String filename)和System.loadLibrary(String libname)的区别
  7. APP价格标签页面设计灵感!明码标价!
  8. Python编程实例(4)
  9. Unity3D开发之画墙、地面分割(户型绘制)
  10. 对六自由度机械臂的运动控制及python实现(附源码)
  11. 计算机音乐A谱,WPSOffice谱写音乐简谱
  12. php调用海康,手把手教你php对接海康api
  13. 第5章 域内横向移动分析及防御
  14. JDK环境配置及Python、Pycharm、Git
  15. 单个JVM下支撑100w线程数vm.max_map_count
  16. Week8 :差分约束,拓扑排序和kahn,强连通图和kosaraju
  17. 原生js实现(别踩白块小游戏)
  18. api-project使用帮助文档
  19. 更改 IE 代理服务器的设置
  20. Spring第一章笔记

热门文章

  1. android源码编译完成之后
  2. *(volatile unsigned long *) 语法
  3. 肯德基champs各个字母代表什么_百度知道
  4. html入门的一些东西
  5. 1.三层交换,ACL,PPP,OSPF,热备
  6. java 文本框怎么属性绑定_如何将对象属性绑定到angular2中的文本框
  7. SpringBoot学习---页面国际化
  8. mysql 字段_【MySql】mysql 字段个数的限制
  9. Spring MVC+Stomp+Security+H2 Jetty 1
  10. Paper Read: Robust Deep Multi-modal Learning Based on Gated Information Fusion Network