标题:用C++编写的一个关于栈的程序出了点问题,请教大家?
只看楼主
hitcolder
Rank: 1
等 级:新手上路
威 望:1
帖 子:124
专家分:0
注 册:2008-10-28
 问题点数:0 回复次数:1 
用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定义的枚举类型之一啊 ,大家谁能给解释下,非常感谢!!
搜索更多相关主题的帖子: 编写 
2008-12-16 16:09
asdjc
Rank: 6Rank: 6
来 自:武汉
等 级:侠之大者
威 望:7
帖 子:98
专家分:487
注 册:2010-1-22
得分:0 
头文件有问题。可能是缺空格,
#include<iostream>
#include <iostream>

2010-04-02 20:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-249598-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.133168 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved