#include <iostream>
#include <stack>
using namespace std;
int main(int argc,char *argv[])
{
const stack<int>::size_type stack_size = 10;
stack<int> istack;
int ix = 0;
while(istack.size() != stack_size)
{
istack.push(ix++);
}
int error_cnt = 0;
while(istack.empty() == false)
{
int value = istack.top(); //将栈顶元素赋值给value
if(value != --ix)
{
cerr << "oops! expected " << ix
<<" received " << value <<endl;
++error_cnt;
}
istack.pop();
}
cout << "There are " << error_cnt <<" errors!" << endl;
return 0;
}
|