#include <iostream> int main() { cout << "Input a hex number: "; int x; cin >> hex >> x; cout << "The hex number you entered was " << x << ".\n"; }
Input a hex number: 10 The hex number you entered as 16.
hex
stream manipulator is sticky, is
confused by this output. What explanation do you give to clear up your
colleague's confusion?
Base manipulators are sticky, but only to the streams to which they're applied;
cin
and cout
are separate streams. Your colleague's setting the base
for cin
to hexadecimal has no affect on cout
, which maintains the
default decimal base.
class T { T() { } }; int main() { T t; }
Your colleague's compiler could have been a bit clearer by pointing out that the class T has no public constructor. The given default constructor has private access, which is the default access for classes, and because the class contains one constructor, the compiler won't supply any other ones.
This page last modified on 3 August 2001.