您的位置:首页 > 编程语言 > C语言/C++

Sample 4.20:ptrstr.cpp

2013-12-02 22:08 423 查看
#include<iostream>
#include<cstring>
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 strcpy(): \n";
cout << animal << " at " << (int *) animal << endl;
cout << ps << " at " << (int *) ps << endl;

ps = new char [strlen(animal) + 1];
strcpy(ps, animal);
cout << "After using strcpy(): \n";
cout << animal << " at " << (int *) animal << endl;
cout << ps << " at " << (int *)ps << endl;
delete [] ps;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: