Complier error

#include "stdafx.h"

#include <iostream>

using namespace std ;

int main ()

{
int x = 6 ;
cout << x ;
x = 9 ;
cout << x += 1 ;
cin.get () ;
return 0 ;
}
<< has higher priority than += so you are not adding to x, but to whatever cout << x returned (which is a reference to cout).
Either wrap the assignment is parenthesis or move it into a separate line.
Okay so I must do..this?

x += 1 ;
cout << x ;

I cannot make it add 1 and show me the answer in one statement?
Last edited on
closed account (zb0S216C)
Wrapping the computation in parentheses will change the order of precedence. It's done like this:

 
cout << ( x += 1 );

Wazzak
Last edited on
Topic archived. No new replies allowed.