To understand this question, you should know that in C ++ string literals such as "lw $" are considered as const char[] as inherited from C. However, this means that you only get operators that are defined for arrays , or in this case, the case of changing the array-to-pointer.
So what happens, you have a string literal, and then add an integer to it, creating a new pointer. Then you try to add another string literal, which again degrades to char* . You cannot add two pointers together, which then generate the error you see.
You are trying to format integers in string format with some separator text. In C ++, the canonical way to do this is with stringstreams:
#include <sstream> string lw(int a, int b) { std::ostringstream os; os << "lw $" << a << "0($" << b << ")\n"; return os.str(); }
source share