C++语言开发示例:04. 字符串指针
ptrstr.cpp
#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 << "!\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;
} 最后更新于1年前
本文由人工编写,AI优化,转载请注明原文地址: C++语言开发示例:04. 字符串指针
推荐阅读
深信服VPN客户端下载:EasyConnect与aTrust零信任访问指南
18992025-10-17
VMware Workstation 16激活码及许可证密钥获取方法
26132025-10-26
百度地图授权弹窗解决方案:商用授权、AK申请与屏蔽方法详解
14112026-03-20
IntelliJ IDEA常见问题解决方案大全:服务面板、Maven报错、启动故障处理
3542026-04-14
使用Cesium.js加载vtu格式(UnstructuredGrid)的文件
282025-12-06
达梦数据库libgeos_c.dll加载失败解决方法:空间数据包安装指南
332026-04-14