标题:【请教】 这两句话为什么不能换
取消只看楼主
piaohai09
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-7-16
 问题点数:0 回复次数:0 
【请教】 这两句话为什么不能换
#include<iostream>
#include<string>
int main()
{
using namespace std;
char animal[20]="bear";
const char* bird="wren";
char* ps;
cout<<animal<<" and ";
cout<<bird<<"\n";
cout<<"Enter a kind of animal:";
cin>>animal;
ps=animal;
cout<<ps<<"s!\n";
cout<<"before using strgy():\n";
cout<<animal<<"at"<<(int*)animal<<endl;
cout<<ps<<"at"<<(int*)ps<<endl;
ps=new char[strlen(animal)+1];//此处为什么不能用 ps=animal;代替
strcpy(ps,animal);
cout<<"after using strcpy():\n";
cout<<animal<<"at"<<(int *)animal<<endl;
cout<<ps<<"at"<<(int *)ps<<endl;
delete[]ps;
return 0;
}
搜索更多相关主题的帖子: include std animal using 
2007-07-17 14:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-156001-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.907957 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved