中国高校课件下载中心 》 教学资源 》 大学文库

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

文档信息
资源类别:文库
文档格式:PPT
文档页数:49
文件大小:376.5KB
团购合买:点击进入团购
内容简介
南京航空航天大学:《程序设计》课程教学课件(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"; }

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档