输入迭代器:只能前向读取的迭代器,支持++,不能--

输出迭代器:只能前向写入的迭代器,支持++,不能--

这两种迭代器最简单,基本只能读取/写入一次

例子:

 

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

template <typename Iter>
void print_range(Iter begin, Iter end)
{
	// 输出
	copy(begin, end,
		ostream_iterator<iterator_traits<Iter>::value_type>(cout, " "));
}

int main()
{
	vector<string> coll;

	// 输入
	copy(istream_iterator<string>(cin), istream_iterator<string>(),
		back_inserter(coll));
	print_range(coll.begin(), coll.end());
	cout << endl;

	sort(coll.begin(), coll.end());

	print_range(coll.begin(), coll.end());
	cout << endl;

	return 0;
}

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-02-20
  • 2021-07-18
  • 2021-08-20
  • 2022-03-09
  • 2022-12-23
猜你喜欢
  • 2021-05-10
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-04-11
  • 2022-12-23
相关资源
相似解决方案