LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > MWH
User Name
Password

Notices


Rate this Entry

Why ios::hex and ios::oct Does not Work in C++

Posted 01-26-2010 at 11:45 PM by MWH
Updated 01-26-2010 at 11:59 PM by MWH

Someone might think ios:ct and ios::hex doesn't work in Linux for some unknown reason. The thing is that I have got to know why it's happening. Actually there is no problem, the thing is by default ios::dec turned on in C++. So we have to turn it off by typing cout.unsetf(ios::dec); before our cout statement or cout<<hex<<21323<<endl;.


Eg:-1.


#include<iostream>

#include<iomanip>

using namespace std;

int main()

{

cout.unsetf(ios::dec); //Turn off decimal mode

cout<<setiosflags(ios::hex)<<12323<<endl; //Hex mode is turned on from now on

return 0;

}


Eg:-2.


#include<iostream>

using namespace std;

int main()

{

cout<<hex<<12323<<endl;/*This is easy because we do not have to type cout.unsetf(ios::dec).This thing automatically turns off ios::dec.*/

return 0;

}


Eg:-3.


#include<iostream>

#include<iomanip>

using namespace std;

int main()

{

cout.unsetf(ios::dec);

cout<<setiosflags(ios::hex)<<setw(5)<<12323<<endl;

return 0;

}



I learned this thing from http://www.learncpp.com/cpp-tutorial...tream-and-ios/
Views 2803 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:48 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration