用C++编写的一个关于栈的程序出了点问题,请教大家?
原程序如下:#include<iostream>
#include<cctype>
#include"stack"
using namespace std;
char get_command();
bool do_command(char command,stack<double>& numbers);
int main()
{
stack<double> numbers;
while(do_command(get_command(),numbers));
return 0;
}
//define the function of get_command()
char get_command()
{
char command;
bool waiting=true;
cout<<"select command and press <enter>: ";
while(waiting)
{
cin>>command;
command=tolower(command);
if(command=='?'||command=='+'||command=='-'||command=='*'||command=='/'||command=='='||command=='q')
waiting=false;
else
cout<<"plesae re-enter the right command:"<<endl<<endl;
}
return command;
}
//define the function of do_command
bool do_command(char command,stack<double> &numbers){
double p,q;
switch(command)
{
case '?':
cout<<"enter a real number:"<<flush;
cin>>p;
if(numbers.push(p)==overflow)
cout<<"the stack is full."<<endl;
else
numbers.push(p);
break;
case '=':
if(numbers.top(p)==underflow)
cout<<"stack empty."<<endl;
else
cout<<p<<endl;
case '+':
if(numbers.top(p)==underflow)
cout<<"stack empty."<<endl;
else
{
numbers.pop();
if(numbers.top(q)==underflow)
{
cout<<"stack has only one number."<<endl;
numbers.push(p);
}
else
{
numbers.pop();
if(numbers.push(p+q)==overflow)
cout<<"stack full:"<<endl;
}
}
break;
case 'q':
cout<<"calculating finish."<<endl;
return false;
}
return true;
}
编译错误如下:
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(46) : error C2065: 'overflow' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(46) : error C2120: 'void' illegal with all types
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(52) : error C2661: 'top' : no overloaded function takes 1 parameters
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(52) : error C2065: 'underflow' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(57) : error C2661: 'top' : no overloaded function takes 1 parameters
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(62) : error C2661: 'top' : no overloaded function takes 1 parameters
D:\Program Files\Microsoft Visual Studio\MyProjects\练习的小程序\区分偶数和奇数.cpp(70) : error C2120: 'void' illegal with all types
Error executing cl.exe.
不明白的是我已经把stack文件包含进去了,为什么还说overflow没有定义呢,它应该是已经由error_code定义的枚举类型之一啊 ,大家谁能给解释下,非常感谢!!