为了账号安全,请及时绑定邮箱和手机立即绑定

C++如何将字符串"a+b+c"转化为公式

C++如何将字符串"a+b+c"转化为公式

C++
烙印99 2019-04-28 15:04:25
我现在是在文件中读取一个公式"a+b+c";然后再主函数中已经定义a=1;b=2;c=3现在我想将a=1;b=2;c=3的值代入从文件读取的字符串中,请问如何编程"依次访问字符串“a+b+c”,遇到字母,就将该字符转换为对应的值 "然后呢?如何计算其结果
查看完整描述

3 回答

?
蓝山帝景

TA贡献1843条经验 获得超7个赞


你试试这段代码,

1

2

3

4

5

6

7

8

9

10

11

12

13

14

string str,stra,strb,strc;

int d,a,b,c;

char a='+';

cin>>str;

d=str.find(a);

stra=str.Substring(0,d);

str=str.Remove(0,d);

d=str.find(a);

strb=str.Substring(0,d);

str=str.Remove(0,d);

strc=str;

a = atoi(stra.c_str());

b = atoi(strb.c_str());

c = atoi(strc.c_str());


 



查看完整回答
反对 回复 2019-04-28
  • 3 回答
  • 0 关注
  • 484 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信