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. c22---枚举

    // // main.c // 枚举基本概念 #include <stdio.h> int main(int argc, const char * argv[]) { // int sex ...

  2. IJKPlayer问题集锦之不定时更新

    1.IJKPlayer 不像系统播放器会给你旋转视频角度,所以你需要通过onInfo的what == IMediaPlayer.MEDIA_INFO_VIDEO_ROTATION_CHANGED去获取 ...

  3. php xml 转array 函数 (原创)

    /** *Author zhudongchang *Date 2015/6/12 原创 *xml 转array 函数 *@param string $xmlStr xml字符串 *@return st ...

  4. WinForm进程 线程

    进程主要调用另一程序,线程 分配工作. 一.进程: 进程是一个具有独立功能的程序关于某个数据集合的一次运行活动.它可以申请和拥有系统资源,是一个动态的概念,是一个活动的实体.Process 类,用来操 ...

  5. 百度地图api的简单应用

    百度地图api 获取经纬度(通过浏览器的) //获取经纬度 window.navigator.geolocation.getCurrentPosition(function(position) { a ...

  6. hdu 1087 A Plug for UNIX 最大流

    题意:http://www.phpfans.net/article/htmls/201012/MzI1MDQw.html 1.在一个会议室里有n种插座,每种插座一个: 2.每个插座只能插一种以及一个电 ...

  7. [ Java ] String 轉型 ArrayList

    Lambda 對我而言一很像天書 這個行 Java code 讓我開始有點些微有 Lambda 感覺 https://stackoverflow.com/questions/10706721/conv ...

  8. poj 2955 Brackets 【 区间dp 】

    话说这题自己折腾好久还是没有推出转移的公式来啊------------------ 只想出了dp[i][j]表示i到j的最大括号匹配的数目--ค(TㅅT)------------------- 后来搜 ...

  9. Bootstrap 有一个 class 属性叫做 well,它的作用是为设定的列创造出一种视觉上的深度感

    Bootstrap 有一个 class 属性叫做 well,它的作用是为设定的列创造出一种视觉上的深度感

  10. MongoDB 学习笔记(五):固定集合、GridFS文件系统与服务器端脚本

    一.count.distinct与group 1.count函数:查询文档数,如下图: 2.distinct:去重,用法:db.runCommand({distinct:"集合名" ...