南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 8-标准模板库STL

第8章标准模板库STL陈哲教授南京航空航天大学计算机科学与技术学院参考网页:https://www.cplusplus.com/reference/stl/
1 第 8 章 标准模板库STL 陈哲 教授 南京航空航天大学 计算机科学与技术学院 参考网页:https://www.cplusplus.com/reference/stl/

8.1标准模板库简介STL(StandardTemplateLibrary)标准模板库是一个高效的C++程序库,它是C++标准中极具特色的一部分。为程序员提供了一个可扩展的应用框架,体现了软件的可复用性。体现了泛型程序设计的思想。数据结构”是学习本章的原理基础
2 8.1 标准模板库简介 • STL(Standard Template Library)标准模板库 是一个高效的C++程序库,它是C++标准中极具 特色的一部分。 • 为程序员提供了一个可扩展的应用框架,体现了 软件的可复用性。体现了泛型程序设计的思想。 • “数据结构”是学习本章的原理基础

8.2 The C++ string ClassC++provides two ways of storingandworking with strings: One method is to store them as C strings incharacterarrayvariables. Another way is to storethemin string classobject.See:https:/www.cplusplus.com/reference/string/string
3 8.2 The C++ string Class • C++ provides two ways of storing and working with strings. • One method is to store them as C strings in character array variables. • Another way is to store them in string class object. See: https://www.cplusplus.com/reference/string/string/

8.2 The C++ string Class (continuedUsingthe string Class? The first step : #include Notice : There is no".h". The next step : using namespace std;
4 8.2 The C++ string Class (continued ) • Using the string Class • The first step : #include Notice : There is no ".h“. • The next step : using namespace std;

#include#includeusing namespace std;void main(void)stringmovieTitle;movieTitle ="Wheels of Fury";cout > movieTitle ;cout << movieTitle<< endl;cin.ignoreO;getline(cin, movieTitle);cout<< movieTitle<< endl;
#include #include using namespace std; void main(void) { string movieTitle; movieTitle = "Wheels of Fury"; cout > movieTitle ; cout << movieTitle << endl; cin.ignore(); getline(cin, movieTitle); cout << movieTitle << endl; }

8.2 The C++ string Class (continued ) Comparing string Objects : use the , =, ==, and != relational operators. For example:setl = "ABC":stringset2 = "XYZ"':stringif (setl < set2)cout<<"setl is less than set2.ln";
6 8.2 The C++ string Class (continued ) • Comparing string Objects : use the , =, ==, and != relational operators. • For example: string set1 = "ABC"; string set2 = "XYZ"; if ( set1 < set2 ) cout << "set1 is less than set2.\n";

8.2 The C++ string Class (continued Other Waysto Declare string Objects:1.stringgaddress;Declares an empty string object.2. string name("Zhang San);3.string personl(person2);person2 : a string object or character array
7 8.2 The C++ string Class (continued ) • Other Ways to Declare string Objects: 1. string address; Declares an empty string object. 2. string name("Zhang San"); 3. string personl(person2); person2 : a string object or character array

8.2 The C++ string Class (continued4. stringsetl(set2, 5);采用set2的前5个字符初始化setl5. stringlineFull(z, 10);initialized with 10z'characters.6. stringfirstName(fullName,0,7);用fullName从位置0开始的7个字符,初始化firstName
8 8.2 The C++ string Class (continued ) 4. string setl(set2, 5); 采用set2的前5个字符初始化set1. 5. string lineFull( 'z', 10); initialized with 10 ' z' characters. 6. string firstName(fullName,0,7); 用fullName 从位置0开始的7个字符,初始 化firstName

8.2 The C++ string Class (continued The string class supports several operators:[I Implements array-subscript notation, as inname [x].Relationaloperators>,V,V",>,m,!例如:
9 8.2 The C++ string Class (continued ) • The string class supports several operators: >>、,>=,<=, == ,!= 例如:

#include#includestd;usingnamespacevoid main(void)stringstrl-"ABC",str2=-"DEF",str3;str3=strl+str2;for (int x = 0; x< str3.size(); x++)cout << str3[x];cout << endl;if (strl< str2)cout<<"strlis less than str2n";elsecout<<"strlis not less than str2ln
#include #include using namespace std; void main(void) { string strl="ABC", str2="DEF", str3; str3 = strl + str2; for (int x = 0; x < str3.size( ); x++) cout << str3[x]; cout << endl; if (strl < str2) cout << "strl is less than str2\n"; else cout << "strl is not less than str2\n"; }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 7-模板.ppt
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 6-异常处理.ppt
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 5-继承多态和虚函数.ppt
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 4-类的高级部分.ppt
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 3-类的基础部分.ppt
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 2-文件操作.ppt
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,二)Chapter 1-C++程序设计基础.ppt
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)09 编译预处理和多文件项目.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)08 文件.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)07 记录类型.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)06 数组.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)05 函数.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)04 控制流.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)03 运算符和表达式.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)02 常量和变量.pptx
- 南京航空航天大学:《程序设计》课程教学课件(PPT讲稿,一)01 计算机和程序.pptx
- 《程序设计》课程教学资源(实验指导)C++语言习题集(南京航空航天大学:陈哲).pdf
- 《程序设计》课程教学资源(书籍文献)Google开源项目风格指南(中文版).pdf
- 长春大学:旅游学院:《Visual FoxPro程序设计》课程教学资源(授课教案,共七章).pdf
- 《计算机导论》课程教学资源(授课教案,教材讲义,共六章).pdf
- 揭阳职业技术学院:《Linux操作系统》课程教学资源(实验教案,共十八个).pdf
- 揭阳职业技术学院:《计算机应用基础》课程授课教案.pdf
- 揭阳职业技术学院:《物联网》课程授课教案.pdf
- 揭阳职业技术学院:《程序设计基础》课程授课教案.pdf
- 揭阳职业技术学院:《办公自动化》课程授课教案.pdf
- 揭阳职业技术学院:《图像处理》课程授课教案.pdf
- 揭阳职业技术学院:《计算机应用基础》课程授课教案.pdf
- 揭阳职业技术学院:《Photoshop制图》课程授课教案.pdf
- 清华大学:《计算机图形学基础》课程教学大纲 Fundamental of Computer graphics(负责人:胡事民).pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)图形学简介.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)视图模型变换.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)双向反射分布函数.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)光线跟踪,递归算法,光线求交.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)参数曲线曲面、Bezier曲线、Bezier曲面.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)网格模型、网格细分和简化.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)网格参数化模型切割的骨架算法.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)B样条曲线曲面.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)光线跟踪加速方法.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)纹理映射.pdf
- 清华大学:《计算机图形学基础》课程教学资源(授课教案)阴影 Shadow.pdf
