STL的Hello World

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


void PrintVector(int v) {
	cout << v << "\t";
}
void test01() {
	// 定义一个容器
	vector<int> v;

	v.push_back(10);
	v.push_back(20);
	v.push_back(30);
	v.push_back(40);

	// 通过STL提供的算法遍历

	vector<int>::iterator pBegin = v.begin();
	vector<int>::iterator pEnd = v.end();
	// 容器中可能存放基本数据类型,也可能存放自定义数据类型
	for_each(pBegin, pEnd, PrintVector);

}

int main() {
	test01();
	return 0;

}
posted @ 2021-11-17 18:16  Gazikel  阅读(17)  评论(0编辑  收藏  举报