cpp05.cpp

来自「C++参考书」· C++ 代码 · 共 35 行

CPP
35 行
字号

// Coded by plusir -- Jan.13.2003.
// Standard C++ Bible -- (P686-24-5)

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

int main()
{
	vector<int> v( 5 ) ;

	vector<int>::iterator it = v.begin(), saveIt = it ;

	*it++ = 10 ;
	*it++ = 15 ;
	*it++ = 20 ;
	*it++ = 25 ;
	*it = 30 ;

	it -= 2 ;
	*it = 100 ;

	cout << "Contents of the vector:" << endl ;
	while ( saveIt != v.end() )
		cout << *saveIt++ << endl ;

	saveIt -= 1 ;
	cout << "Contents of the vector backwards:" << endl ;
	while ( saveIt >= v.begin() )
		cout << *saveIt-- << endl ;

	return 0 ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?