"urocrane" <sa********@yahoo.co.uk> wrote in message
news:b3**************************@posting.google.c om...
I've been working around a sample program thats "suppose" to work,
according to Herbert Schildt-but it doesn't... I'm getting a
redefinition error from struct byte. anyone know whats wrong and how
to fixit? and i need some indepth tutorials about bitwise operators
and bitfield.
struct byte
{
unsigned a : 1;
unsigned b : 1;
//... all the way to unsigned h : 1;
};
union bits
{
char ch;
byte bit;
} ascii; //this program displays the ascii code in binary for
characters
void disp_bits(bits b); /*contains code like if(b.bit.h) cout<<"1 "l;
else cout<<"0 "; */
int main()
{
do
{
cin>>ascii.ch;
cout<<": ";
disp_bits(ascii);
}while(ascii.ch!='q');
return 0;
}
Your compiler may not like "byte." Some compilers have a built-in type byte,
and thus you would be redefining that keyword. Then again, some nonstandard
libraries define byte on their own, so that could be a problem. As your
compiler is saying that byte is being redefined, it seems that it is not a
keyword. You've probably got some library that's defining byte on its own.
Ensure only standard libraries:
This Should be changed to
#include <iostream.h> #include <iostream>
using namespace std;
#include <conio.h> Nothing. do not use it.
#include <fstream.h> #include <fstream>
using namespace std;
Note that you only say "using namespace std;" once.
--
MiniDisc_2k2