View Single Post
  #2 (permalink)  
Old April 19th, 2010, 08:06 AM
meteormatt meteormatt is offline
Authorized User
Join Date: Jan 2010
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to meteormatt Send a message via Yahoo to meteormatt

Originally Posted by Cryotic View Post
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?

// Soln3_4.cpp

/* 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.

#include <iostream>
using std::cout;

const int text = 0x01;
const int binary = 0x02;

const int read = 0x10;
const int write = 0x20;
const int append = 0x40;

int main()
int mode = 0; // File open mode
for(int modeSelect = 0 ; modeSelect<6 ; modeSelect++)
// Set a different mode for each loop iteration
case 0:
mode = text | read;
case 1:
mode = text | write;
case 2:
mode = text | append;
case 3:
mode = binary | read;
case 4:
mode = binary | write;
case 5:
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";

return 0;
There may be have some errors.