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是一个不错的选择 ...
随机推荐
- python接口自动化(四十一)- 发xml格式参数的post请求(超详解)
简介 最近在工作中,遇到一种奇葩的接口,它的参数数据是通过xml,进行传递的,不要大惊小怪的,林子大了什么鸟都有,每个人的思路想法不一样,开发的接口也是各式各样的,如果想要统一的话,必须是提前团队已经 ...
- Lambda动态排序分页通用方法
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; us ...
- OC 中 self 与 super 总结
一段代码引发的思考: @implementation Son : Father - (id)init { self = [super init]; if (self) { NSLog(@"% ...
- 记录下laravel 5.2的auth/logout路由工作不正常的问题
- springBoot jpa uuid生成策略
实体类 import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; @Entity @Table(na ...
- Spring Boot 的配置文件application.properties
Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...
- 【extjs6学习笔记】1.10 初始: 定义类
http://www.extjs-tutorial.com/extjs/define-new-class-in-extjs
- JS获取本地文件并且解析文件内容(XML,TXT)
$(function(){ $("body").on("change", "#file", function (event) { uploa ...
- spark dataframe函数编程
DataFrame 的函数 Action 操作 1. collect() ,返回值是一个数组,返回dataframe集合所有的行 2. collectAsList() 返回值是一个Java类型的数组, ...
- iOS中的崩溃类型
http://blog.csdn.net/womendeaiwoming/article/details/44243571 OS中的崩溃类型 在这里了解一下XCode用来表示各种崩溃类型的术语,补充一 ...