titanandrews
Programmer
Hi,
Either I am doing something wrong or Microsoft C++ compiler is. I took an example from Practial C++ Programming book, page 251. Supposedly the integer 1023 should be printed out in decimal format and then in hex format. But when I run it, there is no difference. I tried printing to file and to stdout and the results are the same. What am I missing here? Many thanks!
Either I am doing something wrong or Microsoft C++ compiler is. I took an example from Practial C++ Programming book, page 251. Supposedly the integer 1023 should be printed out in decimal format and then in hex format. But when I run it, there is no difference. I tried printing to file and to stdout and the results are the same. What am I missing here? Many thanks!
Code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
int myInt = 0x3FF; //1023
ofstream outFile("MyOutputFile.txt",std::ios::out);
outFile << "Hello" << endl; //Print a string
cout << "Hello" << endl ; //Echo to console
outFile.setf(std::ios::dec);
cout.setf(std::ios::dec);
outFile << myInt << endl; //Print an int in decimal format
cout << myInt << endl; //Echo to console
outFile.setf(std::ios::hex);
cout.setf(std::ios::hex);
outFile << myInt << endl; //Print an int in hex format
cout << myInt << endl; //Echo to console
return(0);
}