一、stringl类

1.string构造函数

    string a1("abc");//初始化字符串
cout<<a1<<endl;//abc string a2(, '#');//n个字符
cout << a2 << endl;//###### string a3(a1);//复制
cout << a3 << endl;//abc char c[] = "hello";
string a4(c,);//从起始截取前n个字符
cout << a4 << endl;//hel string a5(c+,c+);//截取一段字符串
cout << a5 << endl;//el string a6(c, ,);//从n1开始截取n2个
cout << a6 << endl;//ell

2.字符串输入

#include<iostream>
#include<string>
using namespace std; int main() { //string str1;
//cin >> str1;//输入字符串方法1
//cout << str1 << endl; string str2;
getline(cin, str2);//输入字符串方法2
cout << str2 << endl;
}

3.使用字符串

(1)比较字符串 比较ASCII码

    int a = ;
if ('abc' > 'daaa') {
a = ;
}
else {
a = -;
}
cout << a << endl;

(2)字符串长度

    string a = "abc";
cout << a.length() << endl;
cout << a.size() << endl;

(3)查找

查找是否包含此字符串,有则返回首字符索引,没有返回 npos

    string a = "aabc";
cout << a.find("bc111")<<endl;

npos表示字符串可存储的最大字符数

二、智能指针模板类

智能指针定义后,离开代码块指针将过期

    auto_ptr<string> str(new string);//C++98方式,过时
unique_ptr<string> str(new string);//C++11 一般使用这个
shared_ptr<string> str(new string);//C++11 如果多个指针指向同一个对象,用这个

三、标准模板库

(18)C++ string和标准模板库的更多相关文章

  1. C++ primer plus读书笔记——第16章 string类和标准模板库

    第16章 string类和标准模板库 1. string容易被忽略的构造函数: string(size_type n, char c)长度为n,每个字母都为c string(const string ...

  2. C++——string类和标准模板库

    一.string类 1.构造函数 string实际上是basic_string<char>的一个typedef,同时省略了与内存管理相关的参数.size_type是一个依赖于实现的整型,是 ...

  3. C++标准模板库Stand Template Library(STL)简介与STL string类

    参考<21天学通C++>第15和16章节,在对宏和模板学习之后,开启对C++实现的标准模板类STL进行简介,同时介绍简单的string类.虽然前面对于vector.deque.list等进 ...

  4. 标准模板库(STL)学习指南之sort排序

    对于程序员来说,数据结构是必修的一门课.从查找到排序,从链表到二叉树,几乎所有的算法和原理都需要理解,理解不了也要死记硬背下来.幸运的是这些理论都已经比较成熟,算法也基本固定下来,不需要你再去花费心思 ...

  5. 标准模板库(STL)学习指南之List链表

    本文转载自天极网,原文地址:http://www.yesky.com/255/1910755.shtml.转载请注明 什么是STL呢?STL就是Standard Template Library,标准 ...

  6. STL标准模板库(简介)

    标准模板库(STL,Standard Template Library)是C++标准库的重要组成部分,包含了诸多在计算机科学领域里所常见的基本数据结构和基本算法,为广大C++程序员提供了一个可扩展的应 ...

  7. 【转】C++标准库和标准模板库

    C++强大的功能来源于其丰富的类库及库函数资源.C++标准库的内容总共在50个标准头文件中定义.在C++开发中,要尽可能地利用标准库完成.这样做的直接好处包括:(1)成本:已经作为标准提供,何苦再花费 ...

  8. 【c++】标准模板库STL入门简介与常见用法

    一.STL简介 1.什么是STL STL(Standard Template Library)标准模板库,主要由容器.迭代器.算法.函数对象.内存分配器和适配器六大部分组成.STL已是标准C++的一部 ...

  9. STL 简介,标准模板库

    这篇文章是关于C++语言的一个新的扩展--标准模板库的(Standard Template Library),也叫STL.  当我第一次打算写一篇关于STL的文章的时候,我不得不承认我当时低估了这个话 ...

随机推荐

  1. 小程序 css 文字溢出,长度过长用 。。。

    word-break: break-all;/*允许在单词内换行*/ text-align: left; /* line-height: 45rpx; */ text-overflow: -o-ell ...

  2. STM32几个IO的工作模式

    浮空,顾名思义就是浮在空中,上面用绳子一拉就上去了,下面用绳子一拉就沉下去了.  开漏,就等于输出口接了个NPN三极管,并且只接了e,b. c极 是开路的,你可以接一个电阻到3.3V,也可以接一个电阻 ...

  3. Design:设计(活动)百科

    ylbtech-Design:设计(活动)百科 设计是把一种设想通过合理的规划.周密的计划.通过各种感觉形式传达出来的过程.人类通过劳动改造世界,创造文明,创造物质财富和精神财富,而最基础.最主要的创 ...

  4. English-spoken

    May i come in? 我可以进来么? May I introduce myself? 我能做个自我介绍么? I'm sorry I didn't hear that clearly. May ...

  5. 项目搭建(三):自定义DLL

    说明:程序中有些自定义的控件类型在TestStack.White框架中没有涉及,需要引入自定义的DLL,通过鼠标点击事件处理 使用:将自定义的ClassLibrary2.dll拷贝到项目/bin/de ...

  6. MongoDB 3.6 开启慢查询

    参考:Profiling Levels:支持一下级别.0 默认的profiler level,profiler 关闭并且不收集数据.1 profiler 收集超过slowms的操作数据.2 profi ...

  7. 带有headers的urllib库爬取

    #请求头 #1.引入模块 from urllib import request #2.操作 #(1)定义目标url base_url = "http://www.langlang2017.c ...

  8. PAT甲级【2019年3月考题】——A1159 Structure_of_a_BinaryTree【30】

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...

  9. Java并发AtomicIntegerArray类

    java.util.concurrent.atomic.AtomicIntegerArray类提供了可以以原子方式读取和写入的底层int数组的操作,还包含高级原子操作. AtomicIntegerAr ...

  10. apache 安装配置 (centos)

    1. 使用yum包安装Apache软件 [root@Apache ~]# yum -y install httpd* [root@Apache ~]# rpm -qa | grep httpd --查 ...