STL编程题1

问题描述

下面的程序输出结果是:

1 2 6 7 8 9

//按从小到大的顺序,且没有重复的
#include <iostream>
#include <iterator>//迭代器
#include <set>//set关联容器
using namespace std;

int main() 
{
	//数组a列表初始化
	int a[] = { 8, 7, 8, 9, 6, 2, 1 };
	// 在此处补充你的代码

	//关联容器,不允许有相同元素
	set<int> v(a,a+7);
	//类模板ostream_iterator,输出流o
	//放到输出流,末尾添加空格
	ostream_iterator<int> o(cout, " ");
	//向量v中的数据通过流迭代器放到输出流o中
	copy(v.begin(), v.end(), o);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/try_again_later/article/details/81436161