可以办到的 但是有一定的难度。。。 我这里有个程序 是我之前写好的 表达式中只能有一个运算符 格式是 a+b a-b a/b a*b 这样的都可以 但是像你上面说的例子 是有点难度的 你可以参考下面的 自己试一试#include
#include
using namespace std;
int jisuan(int i,int &a)
{
switch(i)
{
case 1:
return a;
case 2:
return a*10;
case 3:
return a*100;
case 4:
return a*1000;
case 5:
return a*10000;
}
return -1;
}
void main()
{
int num=0,num1=0,num2=0,num3=-1;
char* c;
char c1;
string str;
cout<<"请输入一道四则运算"<
for (int i=0;i
if (str[i]=='-')
num3=i;
if (str[i]=='+')
num3=i;
if (str[i]=='*')
num3=i;
if (str[i]=='/')
num3=i;
}
for (int j=0;j
c1=str[j];
c=&c1;
num=atoi(c);//这个函数是把字符转换成int
num=jisuan(num3-j,num);
num1+=num;
}
for ( j=num3+1;j
c1=str[j];
c=&c1;
num=atoi(c);//这个函数是把字符转换成int
num=jisuan(str.length()-j,num);
num2+=num;
}
switch(str[num3])
{
case '+':
cout<
case '-':
cout<
case '*':
cout<
case '/':
if(num2==0)
{
cout<<"除数不能为0,程序结束"<
}
cout<
}
}
C++办不到,不好意思