cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Complier error
Complier error
Jun 4, 2011 at 9:07pm UTC
gotBytes
(4)
#include "stdafx.h"
#include <iostream>
using namespace std ;
int main ()
{
int x = 6 ;
cout << x ;
x = 9 ;
cout << x += 1 ;
cin.get () ;
return 0 ;
}
Jun 4, 2011 at 9:30pm UTC
hamsterman
(4538)
<< 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.
Jun 4, 2011 at 9:36pm UTC
gotBytes
(4)
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
Jun 4, 2011 at 9:38pm UTC
Jun 4, 2011 at 9:51pm UTC
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
Jun 4, 2011 at 9:54pm UTC
Topic archived. No new replies allowed.