Issue
This Content is from Stack Overflow. Question asked by Elliot
I am trying to write a program that reads in integers from a file and creates bitwise table. The first line in the file is the numbers of rows (unknown). Each row is two integers (X, Y) that I will use in bitwise operations and print out. Each row will have 6 columns (X, Y, X & Y, X | Y, X ^ Y, ~X). I am stuck at the f for loop to print out the numbers that come from those operations. This is what I have so far:
//Variables
//output of first line of input file is
//number of rows for problem A
int N;
in >> N;
//output of second to N lines of input file
unsigned short X, Y;
in >> X >> Y;
//2D array for bitwise table...?
unsigned short ** bitwiseTable1;
//allocate rows only
bitwiseTable1 = new unsigned short * [N];
//allocating the columns
for (int r = 0; r <= N; r++)
bitwiseTable1[r] = new unsigned short [6];
//Traverse the array
for (int r = 0; r <= N; r++)
for (int c = 0; c < 7; c++)
{
//need to read in X,Y from file ? stuck here!
cout << r << c << r & c << r | c << r ^ c << ~r
cout << X << set(5) << Y << set(6) << (X & Y)
<< set(6) << (X | Y) << set(5) << (X ^ Y)
<< set(6) << (unsigned short)(~X) << end;
`enter code here`}
some of the code I changed to be able to post this so in is really in file, end is end line, set is set width
Thank you for your help!
Solution
This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.
This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.