c++ string char* const char*
2024-08-24 07:03:36
#include <iostream>
#include <string>
#include <cstring>
using namespace std; int main()
{
{
string s = "tom and jerry";
const char* c_s = s.c_str();
cout << "---------------" << endl;
cout << c_s << endl;
cout << s << endl;
} {
const char* c_s = "tom and jerry";
string s(c_s);
cout << "---------------" << endl;
cout << c_s << endl;
cout << s << endl;
} {
string s = "tom and jerry";
char* c;
const int len = s.length();
c = new char[len+];
strcpy(c, s.c_str()); //#include <cstring>
cout << "---------------" << endl;
cout << c << endl;
cout << s << endl;
} {
char* c = "tom and jerry";
string s(c);
cout << "---------------" << endl;
cout << c << endl;
cout << s << endl;
} {
const char* c = "tom and jerry";
char* pc = new char[];
strcpy(pc, c);
cout << "---------------" << endl;
cout << c << endl;
cout << pc << endl;
} return ;
}
最新文章
- 那些年【深入.NET平台和C#编程】
- python集成开发工具
- C#使用 UdpClient 类进行简单通信的例子
- Android.mk学习 笔记
- JSP中的EL
- uvalive 7331 Hovering Hornet 半平面交+概率期望
- 【BZOJ1042】【DP + 容斥】[HAOI2008]硬币购物
- c#判断输入textbox是否为数字
- table行转列
- Selenium之偷懒教程
- cocos2dx 制作单机麻将(一)
- 通过EA导入数据库存在表结构并生成文档
- XAMPP命令之LAMPP
- 转 ORACLE数据库它可以存储 中文 字节或字符
- 《玩转Bootstrap(基础)》笔记
- JS中OOP之模拟封装和继承和this指向详解
- PHPstorm 函数时间注释的修改
- 同步socket处理
- linux 系统 网卡 ethX没有显示IP的处理方式
- GCD LCM UVA - 11388 (思维。。水题)
热门文章
- 关于System.Collections空间
- Emmet 语法大全(缩写语法/sublime 插件)
- 关于Could not parse configuration: /hibernate.cfg.xml的问题
- (Android)View.getHeight或getWidth为0时的一些解决方案
- win7下的mstsc ubuntu下的rdesktop
- 将svn添加到系统服务
- mysql数据库分组(GROUP BY)查询实例
- Linux小白最佳实践:《超容易的Linux系统管理入门书》(连载五)Linux系统的对话方式
- 使用Script元素发送JSONP请求
- cplusplus解析