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版本比较高时,编译代码可能出现的问题
问题是这样产生的,先看这个函数原型:
void someFunc(char *someStr);
再看这个函数调用:
someFunc("I'm a string!");
把这两个东西组合起来,用最新的g++编译一下就会得到标题中的警告。
为什么呢?原来char *背后的含义是:给我个字符串,我要修改它。
而理论上,我们传给函数的字面常量是没法被修改的。
所以说,比较和理的办法是把参数类型修改为const char *。
这个类型说背后的含义是:给我个字符串,我只要读取它。
如何同时接收const类型和非const类型?重载
#include <iostream>
using namespace std; int fuc(char *a)
{
cout << a << endl;
}
int fuc(const char *a)
{
cout << a << endl;
}
int main()
{
char a[] = "hello 123";
fuc(a);
const char b[] = "hello 123";
fuc(b);
}
结果

warning:deprecated conversion from string constant to 'char *' 解决方案的更多相关文章
- 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; ...
- warning:deprecated conversion from string constant to 'char *'
warning:deprecated conversion from string constant to 'char *' 解决方式 #include <iostream> using ...
- 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种字符串赋值方式: ...
- ISO c++11 does not allow conversion from string literal to 'char*'
http://stackoverflow.com/questions/9650058/deprecated-conversion-from-string-literal-to-char
- 将string转换成char*
string 是c++标准库里面其中一个,封装了对字符串的操作 把string转换为char* 有3中方法: 1.data 如: string str="abc"; ch ...
- expected declaration specifiers or '...' before string constant
/work/platform_bus_dev_drv/led_dev.c:52: error: expected declaration specifiers or '...' before stri ...
- Constant Pool和String Constant Pool详解
Constant Pool常量池的概念: 在讲到String的一些特殊情况时,总会提到String Pool或者Constant Pool,但是我想很多人都不太明白Constant Pool到底是个怎 ...
随机推荐
- 命令行连接wifi
ubuntu没有图形界面,插入无线网卡后启动不能连接无线. 看这个帖子 http://askubuntu.com/questions/138472/how-do-i-connect-to-a-wpa- ...
- panel面板
描述:作为承载其他内容的容器的,装载其他组件基础,可折叠.关闭.最大化.最小化和自定义行为.面板可以很容易地嵌入到web页面的任何位置. 其他属性请参考api! 案例1:纯html生成 <div ...
- Django RequestContext用法
模版中的变量由context中的值来替换,如果在多个页面模版中含有相同的变量,比如:每个页面都需要{{user}},笨办法就是在每个页面的请求视图中都把user放到context中. from d ...
- 《IT小小鸟》阅读心得
我是一个不爱看书的人,认为看那些又臭又长废话连篇的书是在浪费时间,但我不认为在那么多的书中没有好书,在一次的职业生涯规划中老师推荐了这本书,一开始认为不值得一看,但还是拿了起来,读了有不少的感触. 书 ...
- 【Java】Eclipse导出jar包与javadoc
1.导出jar包 2.导出javadoc 3.jar包添加javadoc 4.出错解决 参考资料: http://www.cnblogs.com/cyh123/p/3345889.html http: ...
- tomcat集群 (自带Cluster集群)
不用借助其他任何工具,tomcat自身就可以实现session共享,实现集群.以下为大概步骤 1,如果是在同一台机器上,请保持多个tomcat端口(一个tomcat对应三个端口)不相同:如果是不同机器 ...
- JS模板引擎 :ArtTemplate (2)
上一篇初略的介绍了一下javascript中的模板引擎,有兴趣的可以戳 这里 . 这一篇将带着大家一起做一个简易的模板引擎, 上一篇介绍到:模板引擎其实做的就是两件事. 根据一定的规则,解析我们所定义 ...
- 获取iframe中的元素
父窗口中获取iframe中的元素 var ifr = document.getElementById('suggustion').contentWindow.document.body; 在ifram ...
- UML快速指南(摘要)转载
UML 概述: UML是一个通用的建模语言.它最初开始捕捉到复杂的软件和非软件系统的行为,现在它已经成为一个OMG标准. UML提供元素和组件的复杂系统支持的要求. UML遵循面向对象的概念和方法.因 ...
- Effeckt.css项目:CSS交互动画应用集锦
目前,网上有大量基于CSS转换的实验和示例,但它们都过于分散,而Effeckt.css的目标就是把所有基于CSS/jQuery动画的应用集中起来,例如:弹窗.按钮.导航.列表.页面切换等等. Effe ...