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. spark 决策树分类算法demo

    分类(Classification) 下面的例子说明了怎样导入LIBSVM 数据文件,解析成RDD[LabeledPoint],然后使用决策树进行分类.GINI不纯度作为不纯度衡量标准并且树的最大深度 ...

  2. Node.js:文件系统

    ylbtech-Node.js:文件系统 1.返回顶部 1. Node.js 文件系统 Node.js 提供一组类似 UNIX(POSIX)标准的文件操作API. Node 导入文件系统模块(fs)语 ...

  3. 如何用jquery+ajax写省市区的三级联动?(封装和不封装两种方式)-----2017-05-14

    首先,要实现如下图效果, 1.要理清思路: 先做出三个下拉菜单----根据第一个下拉菜单的value值获取第二个下拉列表的内容,第三个同理. 2.用到的数据库表:Chinastates表 规律:根据国 ...

  4. asp.net的TextBox回车触发指定的按钮事件

    一;             event.returnValue = false;             document.all[button].click();         }    }   ...

  5. Vue.js 2 vs Vue.js 3的实现 – 云栖社区

    Vue.js 2 vs Vue.js 3的实现 – 云栖社区 vue.js核心团队已经讨论过将在Vue3实现的变化.虽然API不会改变,但是数据响应机制(译者注:对数据改变的监听和通知)发生了变化.这 ...

  6. 企业级Spring应用的搭建

    本次博客将要对SpringMVC做简单的介绍以及环境的搭建: 概述 Spring 框架是一个开源的平台,属于设计层面框架,整个系统面向接口,是分层的JavaSE/EE开源框架,用于解决复杂的企业应用开 ...

  7. poj1149 PIGS 最大流(神奇的建图)

    一开始不看题解,建图出错了.后来发现是题目理解错了.  if Mirko wants, he can redistribute the remaining pigs across the unlock ...

  8. 使用Windows上Eclipse远程调试Linux上的Hadoop

    一.设置Eclipse运行用户     如果以与Hadoop运行用户名(比如grid)不同的用户运行Eclipse,则无法对Hadoop运行用户所属的文件进行管理,运行Map/Reduce程序也会报& ...

  9. 了解权限控制框架shiro 之实际应用.

    Apache Shiro 1.权限控制分为 a.粗粒度 URL 级别权限控制     b.细粒度方法级别权限控制 2.使用shiro进行权限控制主要有四种主要方式 : a. 在程序中 通过 Subje ...

  10. 关于Linux操作系统层次结构分析

    本文转自http://www.jb51.net/LINUXjishu/214104.html 首先来看一张图(这是Linux操作系统的大致层次结构): 最内层是硬件,最外层是用户常用的应用,比如说fi ...