STL 小白学习(1) 初步认识】的更多相关文章

#include <iostream> using namespace std; #include <vector> //动态数组 #include <algorithm>//算法 void PrintVector(int v) { cout << v<<" "; } /* STL 容器算法迭代器 基本语法 */ void test01() { vector<int> v; //定义一个容器 指定存放的元素类型 v…
map的构造函数 map<int, string> mapS; 数据的插入:用insert函数插入pair数据,下面举例说明 mapStudent.insert(pair<, "student_one")); mapStudent.insert(pair<, "student_two")); mapStudent.insert(pair<, "student_three")); map迭代器 map<int,…
void test01() { //构造方法 pair<, ); cout << p1.first << p1.second << endl; pair<, "assd"); cout << p2.first << p2.second << endl; pair<int, string> p3 = p2; }…
#include <iostream> using namespace std; #include <set> void printSet(set<int> s) { for (set<int>::iterator it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl; } //初始化 void test01(…
#include <iostream> using namespace std; #include <list> void printList(list<int>& mlist) { for (list<int>::iterator it = mlist.begin(); it != mlist.end(); it++) { cout << *it << " "; } cout << endl;…
#include <iostream> #include <stack> //stack 不遍历 不支持随机访问 必须pop出去 才能进行访问 using namespace std; void test01() { //初始化 stack<int> s1; stack<int> s2(s1); //stack操作 //首先是压栈 s1.push(); s1.push(); s1.push(); //返回栈顶元素 cout << "栈顶…
//queue 一端插入 另一端删除 //不能遍历(不提供迭代器) 不支持随机访问 #include <queue> #include <iostream> using namespace std; void test01() { queue<int> q1; q1.push();//尾部插入 q1.push(); q1.push(); q1.pop();//删除队头 cout << q1.back();//返回队尾元素 cout << q1.f…
#include <iostream> #include <deque> //deque容器 双口 using namespace std; void printDeque(deque<int>& d) { for (deque<int>::iterator it = d.begin(); it != d.end(); it++) { cout << (*it) << " "; } cout <<…
#include <iostream> using namespace std; #include <vector> void printVector(vector<int>& v) { for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { cout << (*it) << " "; } cout << endl; }…
#include <iostream> using namespace std; #include <string> //初始化操作 void test01() { //初始化操作 string s1; , 'a'); string s3("abc"); string s4(s3); cout << s1 << endl; cout << s2 << endl; cout << s3 <<…