001
30.03.2006, 08:50 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo, da gibt es verschiedene Möglichkeiten typisierte Daten zu schreiben/lesen.
C++: |
private struct CACHE{ public Int32 dummy1; public Int32 dummy2; public Int32 noch_ein_Ddword; public Int32 ok_genug; } private const int max = 4; private CACHE[] tmp = new CACHE[max]; private string pfad ="cache.dat";
private void Form1_Load(object sender, System.EventArgs e) { int counter = 100; for(int i=0; i < max; i++) { tmp[i].dummy1 = counter; counter++; tmp[i].dummy2 = counter; counter++; tmp[i].noch_ein_Ddword = counter; counter++; tmp[i].ok_genug = counter; counter++; } }
private void btnWrite_Click(object sender, System.EventArgs e) { writeFile(); }
private void writeFile() { FileStream wStream = new FileStream(pfad,FileMode.OpenOrCreate,FileAccess.Write); BinaryWriter bWriter = new BinaryWriter(wStream); for(int i=0; i < max; i++) { bWriter.Write(tmp[i].dummy1); bWriter.Write(tmp[i].dummy2); bWriter.Write(tmp[i].noch_ein_Ddword); bWriter.Write(tmp[i].ok_genug); } bWriter.Flush(); bWriter.Close(); wStream.Close(); }
private void btnRead_Click(object sender, System.EventArgs e) { for(int i =0; i < max; i++) { tmp[i].dummy1 = 0; tmp[i].dummy2 = 0; tmp[i].noch_ein_Ddword = 0; tmp[i].ok_genug = 0; } readFile(); }
private void readFile() { FileStream rStream = new FileStream(pfad,FileMode.OpenOrCreate,FileAccess.Read); BinaryReader bReader = new BinaryReader(rStream); for (int i=0; i < max; i++) { tmp[i].dummy1 = bReader.ReadInt32(); tmp[i].dummy2 = bReader.ReadInt32(); tmp[i].noch_ein_Ddword = bReader.ReadInt32(); tmp[i].ok_genug = bReader.ReadInt32(); } bReader.Close(); rStream.Close(); }
|
-- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe |