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 an output like this:
1 add 2 subtract
But I wanted one like that:
1 add 2 subtract 1