ユーザーの入力 (数式) を受け取り、それをスタックにプッシュしたいと考えています。次に、「(」、数値、または演算子「+」であるかどうかを尋ねるいくつかのルールを実行したいと思います。私の問題は、これまでのところ、どのように判断すればよいかわかりません。具体的には、while ループの最初の if文字が「実際に」数値である場合のステートメント。
#include <stack>
int main()
{
std::stack<char> myStack; // initializing the stack
char line[40];
cin.getline(line, 40); // this and the proceeding line get the input
for (int i = 0; i < 40; i++)
myStack.push(line[i]); //pushing all of the char onto the stack.
while (!myStack.empty()) {
if (myStack item = a number) {
// ^ this is where it doesn't compile.
// I need to figure out how to find out if a char is a number
cout << item << endl;
}
else if (myStack.empty()) {
myStack.push(item);
}
}
}