| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 688 人关注过本帖
标题:程序执行的时候出现错误了
只看楼主 加入收藏
huangyan6611
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2009-4-29
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:1 
程序执行的时候出现错误了

大家帮着改下 谢谢了啊

main.cpp中的文件
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include"stack.h"
const int MaxLength=100;
void PrintMatchedPairs(char *expr)
{
    Stack<int>s(MaxLength);
    int j,length=strlen(expr);
    for(int i=1;i<=length;i++)
    {
        if(expr[i-1]=='(')s.add(i);
        else if(expr[i-1]==')')
            try
            {
              s.Delete(j);
              cout<<j<<" "<<i<<endl;
            }
    catch()
    {
        cout<<"no match for right parenthesis"<<"at"<<i<<endl;
    }
    }
        while(!s.isempty())
        {
            s.Delete(j);
            cout<<"no match for left parenthesis at"<<j<<endl;
        }
}

void main(void)
{
    char expr[MaxLength];
    cout<<"type an expression of length at most"<<MaxLength<<endl;
    cin.getline(expr,MaxLength);
    cout<<"the pairs of matching parenthesis in"<<endl;
    puts(expr);
    cout<<"are"<<endl;
     PrintMatchedPairs(expr);
}


Stack.h中的文件
template<class T>
class Stack
{
    public:
        Stack(int MaxStackSize=10);
        ~Stack(){Delete[]stack;}
        bool isempty()const{return top==-1;}
        bool isfull()const{return top==maxtop;}
        T Top()const;
        Stack<T>& add(const T& x);
        Stack<T>& Delete(T& x);
    private:
        int top;
        int maxtop;
         T *stack;
};
template<class T>
Stack<T>::Stack(int MaxStackSize)
{
    maxtop=MaxStackSize-1;
    stack=new T[MaxStackSize];
    top=-1;
}
template<class T>
T Stack<T>::Top()const
{
    if(isempty())return false;
    else return stack[top];
}
template<class T>
Stack<T>& Stack<T>::add(const T& x)
{
    if(isfull())throw nomem();
    stack[++top]=x;
    return *this;
}
template<class T>
Stack<T>& Stack<T>::Delete(T& x)
{
    if(isempty())return false;
    x=stack[top--];
    return *this;
}


--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\kuo\main.cpp(19) : error C2310: catch handlers must specify one type
D:\Program Files\Microsoft Visual Studio\MyProjects\kuo\main.cpp(23) : error C2317: 'try' block starting on line '15' has no catch handlers
执行 cl.exe 时出错.

main.exe - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: include 
2009-12-18 00:19
sen_lin
Rank: 6Rank: 6
等 级:侠之大者
威 望:3
帖 子:114
专家分:436
注 册:2009-3-24
收藏
得分:20 
你那个catch后怎么加了一个括号啊
2009-12-23 16:24
快速回复:程序执行的时候出现错误了
数据加载中...
 
   



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

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