码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-01-24 00:31:37      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:bsp   ids   常量   filename   pre   复制   字符串   括号   解决   

第1种字符串赋值方式:

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

第2种字符串赋值方式:

    char str[] ="./2017-09-02-10-34-10.xml";
    char *fileName=str;

第3种字符串赋值方式:

char fileName[] ={"./2017-09-02-10-34-10.xml"};//有无大括号都可以

warning: ISO C++ forbids converting a string constant to ‘char*‘ [-Wwrite-strings]

解决办法:采用第2或3种字符串赋值方式

int main(int argc, char *argv[])
{
    char str[] = "";    //先把C++中的string常量复制给C语言形式的字符串变量,再将str赋值给char*形式的C语言字符串。
    argv[2] = str;
}

 

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

标签:bsp   ids   常量   filename   pre   复制   字符串   括号   解决   

原文地址:https://www.cnblogs.com/rainbow70626/p/10311977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!