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

C++: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

时间:2016-12-05 17:12:37      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:void   --   error   end   white   mic   字符串   pre   line   

2016-12-5 16:17:09

----------------------------

在CentOS下开发CTP系统,引入C++程序的过程中,编译(g++ ****)时,有如下提示

【1】  testMdApi.cpp:15:45: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
char *ppInstrumentID[] = {"cu0907", "cu0909"}; // 行情订阅列表
^
testMdApi.cpp:15:45: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

虽然有这样的提示,但它仍然是有效的C++代码,因为所写的char* 是具有c风格的字符串,所以g++不识别

可以选择在编译的时候加上:g++ -Wno-write-strings text.cpp //忽略警告。。。

其实这样是并不是很安全

 


【2】  testMdApi.cpp:21:15: error: ‘::main’ must return ‘int’
void main(void)

不是代码的问题,而是编译器的问题

C语言的 标准允许main函数为void类型

而按照C++的标准 main 必须是int类型

但很多IDE或编译器不一定准守C++标准,比如VS

 

 

 

 

 

 

 

C++: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

标签:void   --   error   end   white   mic   字符串   pre   line   

原文地址:http://www.cnblogs.com/942267027wzmblog/p/6134399.html

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