Chapter 3 - Exercise 4 - Solution gives no output
I did not find out how to write this application/exercise and decided to peek at the code/answer available for download. But when running/debugging the code provided for a solution nothing is ouput to the command line.
Below is the code/solution which did'nt work. Even if it should work, is there a specific reason for the hexadecimal values to be set with the values they were or could you set them to whatever you prefer?
/* This is a good test of your ability to work with hexadecimal values
and individual bits. Remember, each hexadecimal digit defines 4 bits.
There are six different combinations for the file open mode,
read, write or append combined with each of text and binary modes.
You can therefore set modes in a loop with six iterations.
const int text = 0x01;
const int binary = 0x02;
const int read = 0x10;
const int write = 0x20;
const int append = 0x40;
int mode = 0; // File open mode
for(int modeSelect = 0 ; modeSelect<6 ; modeSelect++)
// Set a different mode for each loop iteration
mode = text | read;
mode = text | write;
mode = text | append;
mode = binary | read;
mode = binary | write;
mode = binary | append;
// Determine the mode that is set and output it
if (mode & text)
cout << "mode is (text,";
else if (mode & binary)
cout << "mode is (binary,";
if (mode & read)
cout << "read)\n";
else if (mode & write)
cout << "write)\n";
else if (mode & append)
cout << "append)\n";