看板Programming
标 题改成c++之後就出问题
发信站KKCITY (Sat May 10 22:01:55 2008)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!news.au!zoonews.ee.ntu!news
以下的程式本来是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 ■■■
--