C++求解 fatal error C1004: 发现意外的文件尾
//表达式的计算
#include "stdafx.h"
#include "iostream"
#include "stack"
#include "map"
using namespace std;
class infix2postfix
{
private:
string infix; //用于转换的中缀表达式
string postfix; //后缀表达式
stack<string> stk; //用于存储运算符的堆栈
map<string,int> oper_prio; //用于存储运算符优先级
void set_priority()
{
oper_prio["#"] = 1;
oper_prio["("] = 2;
oper_prio["&&"] = 3;
oper_prio["||"] = 3;
oper_prio[">"] = 4;
oper_prio["<"] = 4;
oper_prio[">="] = 4;
oper_prio["<="] = 4;
oper_prio["!="] = 4;
oper_prio["=="] = 4;
oper_prio["+"] = 5;
oper_prio["-"] = 5;
oper_prio["*"] = 6;
oper_prio["/"] = 6;
oper_prio["%"] = 6;
oper_prio["^"] = 7;
oper_prio[")"] = 8;
}
public:
infix2postfix()
{}
infix2postfix(const string& infixExp):infix(infixExp)
{}
void setInfixExp(const string& infixExp)
{
infix = infixExp;
}
string postfixExp()
{
postfix = "";
set_priority();
stk.push("#");
unsigned int i = 0;
string input, topstk;
for(; i < infix.size(); )
{
topstk = stk.top();
input = infix.substr(i,1);
if( ! oper_prio[input])
postfix += input;
else
{
if(oper_prio[input] > oper_prio[topstk])
{
if( input.compare(")") ==0 )
{
while( topstk.compare("(") != 0 )
{
postfix += topstk;
stk.pop();
topstk = stk.top();
}
stk.pop();
}
else
stk.push(input);
}
else
{
if( input.compare("(") != 0 )
{
postfix += topstk;
stk.pop();
continue;
}
stk.push(input);
}
}
++i;
}
topstk = stk.top();
while( topstk.compare("#") != 0 )
{
postfix += topstk;
stk.pop();
topstk = stk.top();
}
return postfix;
}
}
--------------------编程问答--------------------
在最后面加上";"应该就可以。
--------------------编程问答--------------------
类和结构定义后大括号后面必须有分号
补充:.NET技术 , C#