cpp04.cpp

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

CPP
32 行
字号

// Coded by plusir -- Jan.13.2003.
// Standard C++ Bible -- (P683-24-4)

#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 ;

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

	cout << "Contents of the vector backwards:" << endl ;

	do {
		cout << *--saveIt << endl ;
	} while ( saveIt != v.begin() ) ;

	return 0 ;
}

⌨️ 快捷键说明

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