//一个简单的计算器代码,主要用来练习C++11新标准的编程技术和stl应用
1 #include<iostream>
2 #include<stack>
3 #include<map>
4 #include<set>
5 #include<functional>
6 #include<string>
7 using namespace std;
8
9
10 typedef function<float(float,float)> optionFun;
11 stack<float> snumber;
12 stack<string> soption;
13 map<string,optionFun> optFunMap;
14 map<string,int> optWeightMap;
15
16 #define DECLARE_OPT(opts,preority)
17 optWeightMap[#opts] = int(preority);
18 optFunMap[#opts] = bind([](float a, float b){return a opts b;}, placeholders::_1, placeholders::_2);
19
20
21 void init_option()
22 {
23 DECLARE_OPT(+,1);
24 DECLARE_OPT(-,1);
25 DECLARE_OPT(*,2);
26 DECLARE_OPT(/,2);
27 }
28
29 bool isoption(string op)
30 {
31 auto it = optWeightMap.find(op);
32 return it!=optWeightMap.end();
33 }
34 float recognize_float(const char* pstr, int& width)
35 {
36 char value[24]={0};
37 int dotcount = 0;
38 for(int i=0;pstr[i]!='