用c++实现计算器功能

 可以区分括号,能够计算多位的数字

#include <iostream>
#include <stack>
#include <sstream>
#include <cctype>
//#include <cmath>
class in2pocal
{
private:
    int level0fop(char op) {
    if (op == '*' || op == '/')
        return 2;
    else if (op == '+' || op == '-')
        return 1;
    return 0; 
}
    bool isop(char ch){
        return ch == '+'||ch == '-'||ch == '*'||ch == '/';
    }
    //bool isnum(char ch);不需要这个,头文件里面有现成的
public:
    std::string in2po(const std::string& infix);
};



std::string in2pocal::in2po(const std::string& infix){
    std::stringstream postfix;//字符串流
    std::stack<char> operators;//定义一个承载char类型数据的栈
    bool preisnum = false;
    for (char ch : infix)
    {
        if (std::isalnum(ch))
        {
            if (preisnum)
            {
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值