c++ string vector类
//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
c++ string vector类的更多相关文章
- c++ StrVec等效vector(string)的类
c++ StrVec等效vector<string>的类 知识点 静态成员变量要在类外定义和初始化 allocator类是使用和uninitialized_copy的配合使用,实现stri ...
- Java API —— ArrayList类 & Vector类 & LinkList类
1.ArrayList类 1)ArrayList类概述 · 底层数据结构是数组,查询快,增删慢 · 线程不安全,效率高 2)ArrayList案例 ...
- 转载:C++ vector 类学习笔记
声明:本文转载自http://blog.csdn.net/whz_zb/article/details/6827999 vector简介 vector是STL中最常见的容器,它是一种顺序容器,支持随机 ...
- Java Vector 类
Vector类实现了一个动态数组.和ArrayList和相似,但是两者是不同的: Vector是同步访问的. Vector包含了许多传统的方法,这些方法不属于集合框架. Vector主要用在事先不知道 ...
- 五:Java之Vector类专题
据说期末考试要考到Vector 这个类,出于复习须要在这里就要好好整理下这个类了. 一.基本概念 Vector 是可实现自己主动增长的对象数组. java.util.vector提供了向量类(vect ...
- 谈一谈Vector类
一.关于Vector类的注意事项 1.从 Java 2 平台 v1.2 开始,vector类改进为实现 List 接口,成为 Java Collections Framework 的成员:所以vect ...
- 【stanford C++】容器III——Vector类
主要介绍如下5个容器类——Vector, Stack,Queue,Map和Set,各个都表示一重要的抽象数据类型.另外,各个类都是一些简单类型的值的集合,所以称它们为容器类. 暂且我们先不需要知道它们 ...
- 重写vector类,完成基本功能,不含迭代器
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- Vector类与Enumeration接口
Vector类用于保存一组对象,由于java不支持动态数组,Vector可以用于实现跟动态数组差不多的功能.如果要将一组对象存放在某种数据结构中,但是不能确定对象的个数时,Vector是一个不错的选择 ...
随机推荐
- Chapter 18 MySQL NDB Cluster 7.3 and NDB Cluster 7.4渣翻
Table of Contents 18.1 NDB Cluster Overview 18.2 NDB Cluster Installation 18.3 Configurati ...
- 玩转Docker之常用API(四)
原文地址:http://accjiyun.cn/wan-zhuan-dockerzhi-chang-yong-api-si/ 任何一个开发的平台都会向开发者开发API,以供开发者更加自由地使用平台所提 ...
- a href="javascript:"与a href="#"
<a href="javascript:;"></a> <a href="#"></a> 这两种写法.这两种写法 ...
- WPF:鼠标长时间无操作,窗口隐藏
//设置鼠标长时间无操作计时器 private System.Timers.Timer MouseTimerTick = new System.Timers.Timer(10000); private ...
- iOS 点击左上角系统返回按钮方法
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endBackground) name:UIAppl ...
- Android 常用RGB值及名称
Android 常用RGB值及名称 颜 色 RGB值 英文名 中文名 #FFB6C1 LightPink 浅粉红 #FFC0CB Pink 粉红 #DC143C Crimson 深红/猩红 #F ...
- 浏览器兼容圆角Border-radius的问题
圆角css代码:border-radius只有在以下版本的浏览器:Firefox4.0+.Google Chrome 10.0+.Opera 10.5+.IE9+支持border-radius标准语法 ...
- CheckPoint_vSEC_Cluster_R77.30
CheckPoint_vSEC_Cluster_R77.30 平台: arm 类型: ARM 模板 软件包: Check Point vSEC Gateway R77.30-041.161 Anti- ...
- Windows Phone Emulator 模拟器常用快捷键
在使用Windows Phone 的开发的时候,在目前大家还很难买到真实的Windows Phone 设备的情况下,我们用来调试自己的程序经常用到的可能就是Emulator了.经常会有人问我说,用鼠标 ...
- ZOJ 2112 Dynamic Rankings(二分,树套树)
动态区间询问kth,单点修改. 区间用线段树分解,线段树上每条线段存一颗平衡树. 不能直接得到kth,但是利用val和比val小的个数之间的单调性,二分值.log^3N. 修改则是一次logN*log ...