I am currently working on a project to handle RPN equations and solve them. This includes *, /, +, -, sin, cos, tan, parenthesis, integers, and doubles. I am attempting to use a stack of any-s to handle every variable type. However, when I set my any variable to a value, Visual Studio 2019 shows it is set to "not empty (Small)", and I cannot access the correct value. Here is my code:
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <any>
using namespace std;
int main()
{
stack<any> equation;
any temp;
string input;
getline(cin, input);
int inputLength = input.length();
for (int i = 0; i < inputLength; i++) {
if (input[i] == '(' && input[i + 1] != ' ') {
input.insert(input.begin() + i + 1, ' ');
inputLength++;
}
else if (input[i] == ')' && input[i - 1] != ' ') {
input.insert(input.begin() + i, ' ');
inputLength++;
}
else if (i < inputLength - 2 && input[i] == ')' && (input[i + 2] == '(' || (input[i + 2] >= 0 && input[i + 2] <= 9))) {
input.insert(input.begin() + i + 2, '*');
input.insert(input.begin() + i + 3, ' ');
inputLength += 2;
}
}
stringstream ss;
string temp2;
ss << input;
while (ss >> temp2) {
if (temp2[0] < 0 || temp2[0] > 9) {
temp = "char";
}
else {
temp = 1.0;
}
equation.push(temp);
}
equation.push(temp);
cout << input;
}