warning:deprecated conversion from string constant to 'char *'
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 'char *'的更多相关文章
- warning:deprecated conversion from string constant to 'char *' 解决方案
#include <iostream> using namespace std; int fuc(char *a) { cout << a << endl; } i ...
- warning: deprecated conversion from string constant to 'char*
warning: deprecated conversion from string constant to 'char* #include<iostream> using namespa ...
- deprecated conversion from string constant to ‘char*’
deprecated conversion from string constant to ‘char*’ #include <iostream> using namespace std; ...
- 排错:expected unqualified-id before string constant
一个低级但是不好定位的编译错误,常见的问题是: 1. 语句的 { 括号不匹配. 2. 缺少 : , 特别是类的定义或声明,枚举的定义. 3. 变量名或函数名使用了保留字.
- c++ 中double与string之间的转换,char *
运行代码为 /* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> //#inc ...
- 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 ...
- warning: ISO C++ forbids converting a string constant to 'char*'
第1种字符串赋值方式: char * fileName="./2017-09-02-10-34-10.xml";//这一种字符串赋值方式已经被ISO禁止了 第2种字符串赋值方式: ...
- expected declaration specifiers or '...' before string constant
/work/platform_bus_dev_drv/led_dev.c:52: error: expected declaration specifiers or '...' before stri ...
- leetcode:ZigZag Conversion 曲线转换
Question: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of ...
随机推荐
- IJKPlayer问题集锦之不定时更新
1.IJKPlayer 不像系统播放器会给你旋转视频角度,所以你需要通过onInfo的what == IMediaPlayer.MEDIA_INFO_VIDEO_ROTATION_CHANGED去获取 ...
- 理解和配置 Linux 下的 OOM Killer【转】
本文转载自:http://www.vpsee.com/2013/10/how-to-configure-the-linux-oom-killer/ 最近有位 VPS 客户抱怨 MySQL 无缘无故挂掉 ...
- LDA解决的问题
人类是怎么生成文档的呢?LDA的这三位作者在原始论文中给了一个简单的例子.比如假设事先给定了这几个主题:Arts.Budgets.Children.Education,然后通过学习训练,获取每个主题T ...
- CodeForces 596A
Description After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the ...
- 第8章 MyBatis简介
# 创建一个名称为mybatis的数据库 CREATE DATABASE mybatis; # 使用名称为mybatis的数据库 USE mybatis; # 创建一个tb_user表,有id.nam ...
- (Go)01.Windows 安装 Go语言开发环境以及使用
一.Go语言下载 go语言官方下载地址:https://golang.org/dl/ 找到适合你系统的版本下载,本人下载的是windows msi版本.也可以下载Source自己更深层次研究go语言 ...
- MAVEN 杂记
MAVEN中央仓库 http://repo.maven.apache.org/maven2http://repo1.maven.org/maven2/http://mvnrepository.com/ ...
- logrotate配置文件
一.logrotate配置文件 /etc/logrotate.conf
- 【MFC】虚拟键代码
一:首先介绍键盘消息 系统消息: ALT,F1,——F24等,是由系统内部处理的,程序本身就存在,比如F1是帮助键. WM_SYSKEYDOWN WM_SYSKEYUP WM_SYSCHAR 非系统消 ...
- Laravel5 开启Debug
Laravel默认没有开启Debug,打开需要两步: .env文件中设置APP_DEBUG=true: 把Laravel服务重启一下(摸索出来的). 这只是开启了基本的调试模式,如果需要看更详细的调试 ...