[問題] 定義字串與指標
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
ubuntu 10.04
編譯器版本 g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無使用額外函數庫
問題(Question):
不了解錯誤訊息
餵入的資料(Input):
g++ stringprac.cpp
./a.out
預期的正確結果(Expected Output):
hello
world
錯誤結果(Wrong Output):
stringprac.cpp: In function ‘int main()’:
stringprac.cpp:6: warning: deprecated conversion from string constant to ‘
char*’
stringprac.cpp:9: warning: deprecated conversion from string constant to ‘
char*’
程式碼(Code):(請善用置底文網頁, 記得排版)
1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 char *str = "hello" ;
7 cout << str << endl;
8
9 str = "world";
10 cout << str << endl;
11
12 return 0;
13 }
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.254.147.177
→
10/09 21:51, , 1F
10/09 21:51, 1F
→
10/09 21:53, , 2F
10/09 21:53, 2F
→
10/09 23:05, , 3F
10/09 23:05, 3F
→
10/09 23:10, , 4F
10/09 23:10, 4F
→
10/09 23:11, , 5F
10/09 23:11, 5F
→
10/10 08:04, , 6F
10/10 08:04, 6F