One thing that's very different in C# vs C++ is that in C# you
generally do not read in a large block of data and simply assign it to
memory and then give it a type or structure. In C# you'll either use
a BinaryReader class to read in individual primitive types at a time
or use binary serialization.
You can also use either the BinaryReader or any stream to read raw
bytes into a byte array and then copy the data to appriately typed
members. With unsafe code within c# you can do direct assignment, but
that is generally avoided when not necessary.
A signed short in c++ would be a System.Int16 or "short" in c#. An
unsigned short would be System.UInt16 or "ushort".
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 1 Feb 2007 12:47:51 -0500, "Marc Ouellette"
<ad***@scp-solutions.com.nospamwrote:
>Hi Everyone,
I am currently reading Binary files in C++Builder using the code below.
Removed some error chacking to make the code simpler to read.
std::ifstream fin;
fin.open(filename.c_str(), std::ios::in|std::ios::binary);
// read the image from file into memory
fin.read((char *)ptr, sizeof(T) * numCells);
fin.close();
I am new to C# and would like to read the same file. In the case above T is
an short.
What would be the quickest way to read it if I already know how many shorts
to read(numCells) and what is the C++ short to C# equivalent(int)?
Thanks,
Marc