改成c++之後就出問題

看板Programming作者時間17年前 (2008/05/11 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
以下的程式本來是c語言 但我改為c++ #include <iostream> using namespace std; int main(){ char *s3,*s5; s3=malloc(10 * sizeof(char)); strcpy(s3,"Welcome"); s5=malloc(15 * sizeof(char)); strcpy(s5,"Good morning"); cout<<"first s3="<<s3<<endl; cout<<"first s5="<<s5<<endl; s3=s5; cout<<"second s3="<<s3<<endl; cout<<"second s5="<<s5<<endl; printf("second s3=%s\n",s3); printf("second s5=%s\n",s5); strcpy(s5,"123"); cout<<"third s3="<<s3<<endl; cout<<"third s5="<<s5<<endl; system("pause"); return 0; } 就會在 s3=malloc(10 * sizeof(char)); 這一行出現 5 C:\Documents and Settings\桌面\新文件5.cpp invalid conversion from `void*' to `char*' 請問我該如何處理呢 謝謝 -- ┌─────KKCITY─────┐ KKBOX 可立刻 聽音樂 bbs.kkcity.com.tw 想聽什麼歌 通通不必等 └──From:59.112.202.12 ──┘ http://www.kkbox.com.tw ■■ --
文章代碼(AID): #189UBV00 (Programming)
文章代碼(AID): #189UBV00 (Programming)