Well, I was "googleing" for some code, and even though I asked for C++, it
seems I ended up with some C# code, which I cannot use.
So I tried the following C++ code:
unsigned char *pixels = ...
char *charpixels = reinterpret_cast<char*>(pixels);
fstream file;
file.open("chars.dat", ios::out);
file.write(charpixels, count);
Now the code compiled, but it doesn't seem to write the correct byte.
Does reinterpret_cast not work right?
"Ananya" wrote:
I am trying to create a file of bytes from my character array
char* chars with length int count.
I wrote the code:
FileStream file = new FileStream(S"chars.dat", FileMode::Create,
FileAccess::Write);
BinaryWriter binary = new BinaryWriter(file);
binary.write(chars, count);
binary.close();
My compiler doesn't recognize FileStream and BinaryWriter.
I tried:
using namespace System::IO;
but it doesn't recognize that either?
Is my code correct, and what "using" or "include" do I need?
By the way, in new FileStream(S"chars.dat", ...), what does the "S" mean?
Thanks for reading this.
You should decide whether you want to use standard C++ or managed C++.
C++ of VS2002/2003. For managed C++ questions, you would also be better
to use the group "microsoft.public.dotnet.languages.vc".
The second code you showed is standard C++. You need to open with
ios::binary.