Lets see what your code does, and clarify it.
int l = 1;
for(l = l; l > 0; l--) The statement l = l is useless, it does nothing. Replace it with the previous line.
for(int l = 1; l > 0; l--) Now, it should be pretty obvious that this just execute once, so it is equivalent to:
int l = 1; But you actually never use l, so you can just get rid of it.
Now for the body of the loop:
int q = -2;
string n1 = "1+5";
int n;
int e;
stringstream(n1[q=q+2]) >> n;
stringstream(n1[q=q+2]) >> e;
cout << n + e << endl; It should be clear that n1[q=q+2] just evaluates to n1[0] and then n[2] . Clearly, this takes the first character and gives it to a temporary stringstream object, then does the same for the third character. All the stringstream does is convert that character to a number. If you only need to convert one character to one number, then you can do this on your own simply like this:
int n = n1[0] - '0';
int e = n1[2] - '0';
If you need to parse anything more complicated than a simple three-character string, you will need a lot more work.
At the end, of course, your program is equivalent to:
int main() {
int n = '1' - '0';
int e = '5' - '0';
cout << n + e << endl;
return 0;
}; Which, in turn, is equivalent to:
int main() {
cout << 1 + 5 << endl;
return 0;
};
I wanted to show this reduction to show that there is no special logic in your code, no parsing, it is just a circumvented way to print 1 + 5, but it cannot do anything else.
I think that the first thing you should look at is "tokenizing" which means to split up a string (or stream input) into a set of tokens (numbers, operators, parentheses, etc.). This is not something stringstream does automatically, you will have to either use a more powerful tool, or program your own tokenizer by extracting one character after another (with the help of stringstream).