1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include<iostream> #include<cstring> using namespace std; char *get(char *str); int main() {
char c[10]; char *ch; cout<<"请输入你的名字!"; cin>>c; ch=get(c); cout<<"你的名字是:"<<ch<<endl; delete []ch; ch=get("Jack"); cout<<"你的名字是:"<<ch<<endl; delete []ch; return 0; } char *get(char *str) { char *p=new char[strlen(str)+1]; strcpy(p,str); //cout<<p; return p; }
|