Hello everyone!
Well, I have a starnge problem.
Here is the code, very simple:
#include <iostream.h>
#include <fstream.h>
typedef short int type;
int main () {
fstream file;
file.open("file.bpd", ios::in | ios:
ut);
type wr, rd;
cout << "writing..." << endl;
for (int i = 0; i < 3; i++) {
cout << "wr: ";
cin >> wr;
file.seekp(0, ios::end);
file.write((char *)&wr, sizeof(type));
}
cout << "reading...." << endl;
for (int i = 0; i < 3; i++) {
int poz = i*sizeof(type);
file.seekg(poz, ios::beg);
file.read((char *)&rd, sizeof(type));
cout << "rd: " << rd << endl;
}
file.close();
}
Problem occures when I try to write number 10 in file. After that everything in "file.bpd" gets corrupted.
Has anyone have some idea what is causing the problem?
Regards, Goran!
Well, I have a starnge problem.
Here is the code, very simple:
#include <iostream.h>
#include <fstream.h>
typedef short int type;
int main () {
fstream file;
file.open("file.bpd", ios::in | ios:
type wr, rd;
cout << "writing..." << endl;
for (int i = 0; i < 3; i++) {
cout << "wr: ";
cin >> wr;
file.seekp(0, ios::end);
file.write((char *)&wr, sizeof(type));
}
cout << "reading...." << endl;
for (int i = 0; i < 3; i++) {
int poz = i*sizeof(type);
file.seekg(poz, ios::beg);
file.read((char *)&rd, sizeof(type));
cout << "rd: " << rd << endl;
}
file.close();
}
Problem occures when I try to write number 10 in file. After that everything in "file.bpd" gets corrupted.
Has anyone have some idea what is causing the problem?
Regards, Goran!