我正在编写一个程序,将一个parathensized表达式转换为数学表达式,并对其进行评估.我已经写好了计算位.
我正在为操作数使用堆栈,并为数字使用队列.向堆栈添加操作数不是问题,但我需要确定输入字符是否为整数,如果是,则将其添加到队列中.这是一些代码:
cout << "Enter the numbers and operands for the expression";
string aString;
do
{
cin >> aString
if (aString = int) // function to convert to read if int, convert to int
{
c_str(...);
atoi(...);
istack.push(int);
}
}
Run Code Online (Sandbox Code Playgroud)
那就是我现在被困住的地方.我知道我将不得不使用c_str和atoi将其转换为int.我采取了错误的做法吗?