1
Hi, I’m starting to create an equation interpreter, I want to replace the operators with words, but things aren’t going well...
main.cpp
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
//disables any deprecation warning
#pragma warning(disable : 4996)
//usings
using std::vector;
using std::string;
using std::cout;
string repops(string expr) {
string iexpr = expr;
for (int i = 0; i < iexpr.length(); i++) {
char& c = iexpr[i];
if (c == '+') {
iexpr.replace(i, i, " add ");
}
if (c == '-') {
iexpr.replace(i, i, " subtract ");
}
if (c == '*') {
iexpr.replace(i, i, " multiply ");
}
if (c == '/') {
iexpr.replace(i, i, " divide ");
}
}
return iexpr;
}
int main() {
cout << repops("1+2-1");
std::cin.get();
return 0;
}
I have a way out like this:
1 add 2 subtract
But I wanted one like this:
1 add 2 subtract 1
You are on stackoverflow
– HelloWorld
Your English is bad? No Worry, because we Speak Portuguese here! Don’t post questions in English, Please!
– Victor Stafusa