[問題] char*

看板C_and_CPP (C/C++)作者 (VF-17)時間15年前 (2010/08/30 15:09), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串1/1
遇到的問題: 請問如何在main,a能輸出b[ ]的內容? 開發平台:Dev-C++ 有問題的code: (請善用置底文標色功能) #include <windows.h> #include <iostream> #include <string> using namespace std; void asd(char* AAA); int main (void) { char* a = new char[8]; cout << " &a " << &a << endl; asd(a); cout << a << ";\n"; system("PAUSE"); return 0; } void asd(char* AAA) { cout << " &AAA " << &AAA << endl; char b[ ] = {"abcdefg"}; AAA = b; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.241.189

08/30 15:14, , 1F
AAA=b那行改用strcpy
08/30 15:14, 1F

08/30 15:15, , 2F
void asd( char * * AAA );
08/30 15:15, 2F

08/30 15:24, , 3F
感謝一樓 lol
08/30 15:24, 3F

08/30 18:31, , 4F
你的b是區域變數,函數返回之後就銷毀了
08/30 18:31, 4F
文章代碼(AID): #1CUraxby (C_and_CPP)
文章代碼(AID): #1CUraxby (C_and_CPP)