改成c++之後就出問題
以下的程式本來是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 ■■■
--
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):