Cout << doesn't work within loop

Here's a fragment of what I'm trying to launch:

for (int i=0; i++; i<=3)
for (int j=0; j++; j<=3)
cout << (m_main[i][j]).a+(m_main[i][j]).b+(m_main[i][j]).c << "";
cout << "\n";

m_main is a matrix whose elements are arranged 3-element sets. The loop above is supposed to display part of its elements presented as sums of the three components.

Why doesn't this approach work?

It displays nothing instead of the i*j-grid, yet when the procedure

cout << (m_main[i][j]).a+(m_main[i][j]).b+(m_main[i][j]).c

is used alone with substituted i and j, it works fine.

The compiler doesn't find any errors.

Thanks for your help!
Last edited on
closed account (o1vk4iN6)
i would put brackets around the addition such that
cout << (... + ... + ...) << endl;
No, that didn't help. :/

Also, endl is redundant here because it would break the line.

You could try, cout << m_main[i][j].a << m_main[i][j].b << m_main[i][j].c << endl;, if you haven't, already.

And use this, if you need spaces between each of the outputs.
cout << m_main[i][j].a << " " << m_main[i][j].b << " " << m_main[i][j].c << " " << endl;
Last edited on
for (int i=0; i<=3; i++)
for (int i=0; i++; i<=3)
What type are a, b and c, and just what do you think those parentheses are doing other than making your code less readable?

What do you mean it displays nothing?

Oh no, how the ... could I?!..

Well, thanks, Caligulaminus. It must be okay now. Sorry for my stupidity.
Last edited on
Topic archived. No new replies allowed.