//string对象的初始化
#include <iostream>
#include <string> //typedef std::basic_string<char> string;
using namespace std; typedef string String; int main()
{
// with no arguments
string s1; //默认构造函数:没有参数或参数有默认值
String s2("hello"); //普通构造函数 String就是string
s1 = "Anatoliy"; //赋值运算符
String s3(s1); //拷贝构造函数 string s3 =s1;
cout << "s1 is: " << s1 << endl;
cout << "s2 is: " << s2 << endl;
cout << "s3 is: " << s2 << endl; // first argument C string
// second number of characters
string s4("this is a C_sting", );
cout << "s4 is: " << s4 << endl; // 1 - C++ string
// 2 - start position
// 3 - number of characters
string s5(s4, , ); // copy word from s3 cout << "s5 is: " << s5 << endl; // 1 - number characters
// 2 - character itself
string s6(, '*');
cout << "s6 is: " << s6 << endl; // 1 - start iterator(迭代器 )
// 2 - end iterator(迭代器 )
string s7(s4.begin(), s4.end() - );
cout << "s7 is: " << s7 << endl; // 通过=初始化string对象
string s8 = "Anatoliy";
cout << "s8 is: " << s8 << endl; string s9 = s1 + "hello"+ s2; //s1 + "hello"+ s2的结果是string类型的对象(变量)
cout << "s9 is: " << s9 << endl;
return ;
}

s1 is: Anatoliy
s2 is: hello
s3 is: Anatoliy
s4 is: this is aC
s5 is: s aC
s6 is: ***************
s7 is: this
s8 is: Anatoliy
s9 is: Anatoliyhellohello

最新文章

  1. 【SQLServer】DBHelper即C#数据库底层封装
  2. Nginx 1.10.2 发布,高性能 Web 服务器
  3. HDU2255-奔小康赚大钱-二分图最大权值匹配-KM算法
  4. [DiocpRPC]介绍与安装
  5. [转]显示文件命令:cat、more、less、tail、touch详解
  6. unix more命令
  7. 把GIF背景变透明
  8. 消息中间件选型分析——从Kafka与RabbitMQ的对比来看全局
  9. 【XSS】对抗蠕虫 —— 如何让按钮不被 JS 自动点击
  10. Spring Boot 整合 docker
  11. Mybatis项目中不使用代理写法【我】
  12. 1.1.18 Word里将“字体加红”自定义为快捷方式
  13. Hbase记录-ZooKeeper API
  14. CentOS6.x网易163yum源配置
  15. 【转载】Springboot整合 一 集成 redis
  16. main方法介绍
  17. IOCP IO完成端口
  18. Singer 学习十三 发现模式
  19. (第十二周)Debug阶段成员贡献分
  20. VMware上配置DPDK环境并运行实例程序

热门文章

  1. linux下的idea的界面问题,错位以及各种...
  2. GCC的内存边界对齐
  3. JDBC连接数据库(Servlet+JSP)
  4. 锁丶threading.local丶线程池丶生产者消费者模型
  5. 【经验总结】datagrid锁定列后重新加载时出现错位问题的解决
  6. iis6.0 建立站点
  7. 【Linux/Ubuntu学习 10】unbuntu 下 eclipse 中文乱码的解决
  8. Spring 的AOP
  9. python any all函数
  10. 如何在Ubuntu server中修改IP