warning:deprecated conversion from string constant to ‘char *’ 解决方式

#include <iostream>
using namespace std; int fuc(char *a)
{
cout << a << endl;
}
int main()
{
fuc("hello");
}

Linux 环境下当GCC版本号比較高时,编译代码可能出现的问题。

主要原因是:

char * 指针指向的字符串是同意改动的,将其作为形參。意味着在函数的某处代码可能改动其指向字符串。

而理论上,我们传给函数的字面常量是没法被改动的。

解决方法1.

把函数形參 參数类型改动为const char *。

解决方法2.

假设肯定函数中不会对形參指向变量进行改变。

能够用(char *)进行强制转换。

warning:deprecated conversion from string constant to &#39;char *&#39;的更多相关文章

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

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

  2. warning: deprecated conversion from string constant to 'char*

    warning: deprecated conversion from string constant to 'char* #include<iostream> using namespa ...

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

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

  4. 排错:expected unqualified-id before string constant

    一个低级但是不好定位的编译错误,常见的问题是: 1. 语句的 { 括号不匹配. 2. 缺少 : , 特别是类的定义或声明,枚举的定义. 3. 变量名或函数名使用了保留字.

  5. c++ 中double与string之间的转换,char *

    运行代码为 /* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> //#inc ...

  6. 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 ...

  7. warning: ISO C++ forbids converting a string constant to 'char*'

    第1种字符串赋值方式: char * fileName="./2017-09-02-10-34-10.xml";//这一种字符串赋值方式已经被ISO禁止了 第2种字符串赋值方式: ...

  8. expected declaration specifiers or '...' before string constant

    /work/platform_bus_dev_drv/led_dev.c:52: error: expected declaration specifiers or '...' before stri ...

  9. leetcode:ZigZag Conversion 曲线转换

    Question: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of ...

随机推荐

  1. vue.js 父组件如何触发子组件中的方法

    组件 什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊 ...

  2. 南海区行政审批管理系统接口规范v0.3(规划) 2.业务申报API 2.1.businessApply【业务申报】

    {"v_interface":"2015987654327","c_project":"NH09A102"," ...

  3. 43.qt通过qss自定义外观

    样式: 文件格式类型: candy.qss /* R1 */ QDialog { /*设置背景图片*/ background-image: url(:/images/background.png); ...

  4. C# net winform wpf 发送post数据和xml到网页

    由于项目需要发送数据到网页 这里用aspx做测试 采用post以及get发送数据,页面进行数据  首先这个东西很简单很简单,基本上学过的都会,但是原谅一直搞cs几乎不搞bs的猿类吧.三四年没接触bs. ...

  5. Py基础+中级

    原文 Py学习博客 1:https://www.cnblogs.com/fu-yong/p/8060198.html2:while True:just do it 三.Python的默认编码 ▷pyt ...

  6. MySQL 5.6 Reference Manual-14.3 InnoDB Transaction Model and Locking

    14.3 InnoDB Transaction Model and Locking 14.3.1 InnoDB Lock Modes 14.3.2 InnoDB Record, Gap, and Ne ...

  7. 【转载】Java实现word转pdf

    最近遇到一个项目需要把word转成pdf,GOOGLE了一下网上的方案有很多,比如虚拟打印.给word装扩展插件等,这些方案都依赖于ms word程序,在java代码中也得使用诸如jacob或jcom ...

  8. oracle 编译包的时候,一直提示正在编译

    select b.sid,b.serial#,b.machine,b.terminal,b.program,b.process,b.status from v$lock a , v$session b ...

  9. Ubuntu14.04引导菜单修复

    原文链接:http://www.metsky.com/archives/636.html 独立分区下的Ubuntu引导菜单修复有点麻烦,执行挂载等命令时要小心检查,修复此类引导,首先需要确保当前系统和 ...

  10. 实验1 OpenGL初识

    实验预备知识 Windows下的OpenGL编程步骤简单介绍详见课程实验教学博客-实验准备安装GLUT包与创建工程: http://www.cnblogs.com/opengl/archive/201 ...