//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类的更多相关文章

  1. c++ StrVec等效vector(string)的类

    c++ StrVec等效vector<string>的类 知识点 静态成员变量要在类外定义和初始化 allocator类是使用和uninitialized_copy的配合使用,实现stri ...

  2. Java API —— ArrayList类 & Vector类 & LinkList类

    1.ArrayList类     1)ArrayList类概述         · 底层数据结构是数组,查询快,增删慢         · 线程不安全,效率高     2)ArrayList案例   ...

  3. 转载:C++ vector 类学习笔记

    声明:本文转载自http://blog.csdn.net/whz_zb/article/details/6827999 vector简介 vector是STL中最常见的容器,它是一种顺序容器,支持随机 ...

  4. Java Vector 类

    Vector类实现了一个动态数组.和ArrayList和相似,但是两者是不同的: Vector是同步访问的. Vector包含了许多传统的方法,这些方法不属于集合框架. Vector主要用在事先不知道 ...

  5. 五:Java之Vector类专题

    据说期末考试要考到Vector 这个类,出于复习须要在这里就要好好整理下这个类了. 一.基本概念 Vector 是可实现自己主动增长的对象数组. java.util.vector提供了向量类(vect ...

  6. 谈一谈Vector类

    一.关于Vector类的注意事项 1.从 Java 2 平台 v1.2 开始,vector类改进为实现 List 接口,成为 Java Collections Framework 的成员:所以vect ...

  7. 【stanford C++】容器III——Vector类

    主要介绍如下5个容器类——Vector, Stack,Queue,Map和Set,各个都表示一重要的抽象数据类型.另外,各个类都是一些简单类型的值的集合,所以称它们为容器类. 暂且我们先不需要知道它们 ...

  8. 重写vector类,完成基本功能,不含迭代器

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  9. Vector类与Enumeration接口

    Vector类用于保存一组对象,由于java不支持动态数组,Vector可以用于实现跟动态数组差不多的功能.如果要将一组对象存放在某种数据结构中,但是不能确定对象的个数时,Vector是一个不错的选择 ...

随机推荐

  1. <Win7硬件故障分析>

    查看当前系统正在运行的硬件信息. 右击计算机——属性——设备管理器看到下面: 一些常见的硬件故障: 主板故障 >开机不正常,偶尔出现突然的断电现象 >明明自己选择了关机,但是还是无法关机或 ...

  2. Quartz.NET持久化

    Quartz.NET所用到的数据库表结构 官方提供的各种数据库脚本:https://github.com/quartznet/quartznet/tree/master/database/tables ...

  3. AJPFX总结java创建线程的三种方式及其对比

    Java中创建线程主要有三种方式: 一.继承Thread类创建线程类 (1)定义Thread类的子类,并重写该类的run方法,该run方法的方法体就代表了线程要完成的任务.因此把run()方法称为执行 ...

  4. html5的使用

    <!DOCTYPE html><html lang="en"><head> <meta charest="UTF-8" ...

  5. ${fn:} 函数

    调用这样一个头文件<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions " ...

  6. Yii2.0 高级版安装 windows

    最近在学习yii2.0 在安装高级版的时候遇到一些问题 索性解决了 下面分享一下 一.关于下载 自行百度,在Yii Framework 中文社区 下载专区下载高级应用程序模板(这边下载用电信网络不用下 ...

  7. HTML5 参数传递

    页面显示效果,如下图: 主页面代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  8. uvm_tlm——TLM1事务级建模方法(一)

    TLM(事务级建模方法,Transaction-level modeling)是一种高级的数字系统模型化方法,它将模型间的通信细节与函数单元或通信架构的细节分离开来.通信机制(如总线或者FIFO)被建 ...

  9. HDU4302 线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4302 , 可以用线段树,也可以STL中的map,multiset,优先队列中的任何一个解决(可我只会线 ...

  10. linux 命令——42 kill (转)

    Linux 中的kill命令用来终止指定的进程(terminate a process)的运行,是Linux下进程管理的常用命令.通常,终止一个前台进程可以 使用Ctrl+C键,但是,对于一个后台进程 ...