【Qt】warning: ISO C++11 does not allow conversion from string literal to char

環境

IDE:Qt creator 4.11.0

編譯器:MinGW 5.3.0 32bit for C++

 

問題

char *pszTip = "Press 'Q' exit application.\n";

 

編譯後警告如下

..\QThreadTest\MyThread.cpp:14:20: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
     char *pszTip = "Press 'Q' exit application.\n";

 

解決方法

1、增加const標識符後,警告消失。

2、C++11新特性,C++98沒有這個問題。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章