关于标准模板库中的一个堆栈问题,不明白错的原因,请高手指点?
#include <iostream.h>#include <stack>
int main()
{
int n;
double item;
stack<double>numbers;//总是说这步有问题,不知道哪里的问题阿?
cout<<"enter n numbers and print them in reverse order."<<endl;
cin>>n;
cout<<endl;
for(int i=0;i<n;i++)
{
cin>>item;
numbers.push(item);
}
cout<<endl<<endl;
while(!numbers.empty())
{
cout<<numbers.top()<<" ";
numbers.pop();
}
cout<<endl;
return 0;
}
编译结果:
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(8) : error C2065: 'stack' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(8) : error C2062: type 'double' unexpected
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(15) : error C2065: 'numbers' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(15) : error C2228: left of '.push' must have class/struct/union type
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(18) : error C2228: left of '.empty' must have class/struct/union type
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(18) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.