第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 <string>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 <string> Notice : There is no ".h“. • The next step : using namespace std;
#include<iostream>#include<string>using namespace std;void main(void)stringmovieTitle;movieTitle ="Wheels of Fury";cout << movieTitle<< endl;cin >> movieTitle ;cout << movieTitle<< endl;cin.ignoreO;getline(cin, movieTitle);cout<< movieTitle<< endl;
#include <iostream> #include <string> using namespace std; void main(void) { string movieTitle; movieTitle = "Wheels of Fury"; cout << movieTitle << endl; cin >> movieTitle ; cout << movieTitle << endl; cin.ignore(); getline(cin, movieTitle); cout << movieTitle << endl; }