C++中如何将vector中的元素倒序输出?

#include 
#include 
using namespace std;
int main(){
	vector vec;
	for (int i = 0; i < 5; ++i) vec.push_back(i);
	
	vector::reverse_iterator it;
	for (it = vec.rbegin(); it != vec.rend(); it++)
		cout<<*it<<" ";
	
	cout<

或者 类似功能可以用栈实现

#include 
#include 
using namespace std;
int main(){
	stack stk;
	for (int i = 0; i < 5; ++i) stk.push(i);
	
	while(stk.size()) cout<

 

你可能感兴趣的:(STL)