setsetiosflags's hex and oct flags doesn't work

i was trying out setsetiosflags flags but when i tried this example:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>

using std::cout;
using std::endl;
using std::setiosflags;
using std::ios;

int main()
{
     cout<<setiosflags (ios::hex)<< 100 << endl;
return 0;
}

it output this:
100

Even when i tried ios::oct it's the same output.
For further information see
http://www.cplusplus.com/reference/ios/ios_base/setf/ in combination with
http://www.cplusplus.com/reference/iomanip/setiosflags/

hex is not an independent format flag.




You forgot to turn off dec flag which have precedence over hex: cout << std::resetiosflags(ios::dec) << setiosflags(ios::hex) << 100 << endl;
If you need to set only one flag, use manipulators: cout << std::hex << 100 << endl;

Or, as cire said, use setf() member function: cout.setf(ios::hex, ios::basefield);
Last edited on
thanks MiiNiPaa and cire for your help now i understand it and it is working now
Last edited on
Topic archived. No new replies allowed.