View Single Post
  #1 (permalink)  
Old February 12th, 2010, 01:09 PM
Cryotic Cryotic is offline
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default 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?


// 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
switch(modeSelect)
{
case 0:
mode = text | read;
break;
case 1:
mode = text | write;
break;
case 2:
mode = text | append;
break;
case 3:
mode = binary | read;
break;
case 4:
mode = binary | write;
break;
case 5:
mode = binary | append;
break;
}

// 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;
}