I've a program written in C++ to read binary files. And I'm writing the same program in C#. But in some cases C# is generating wrong byte.
C++ Code
ifstream s(argv[1], fstream::binary);
unsigned char b;
while(s.good())
{
s >> b;
//...
//Some other code
}
C++ runs fine.
Equivalent C# Code
BinaryReader br = new BinaryReader(new FileStream("filename.bat", FileMode.Open));
byte b;
while(br.BaseStream.Position != br.BaseStream.Length && br.BaseStream.CanRead)
{
b = br.ReadByte();
//...
// some other code
}
Some values of C# are not the same as C++ Please help thank you.