?
2012-08-09 11:46:49 UTC
#include
#include
using namespace std;
ofstream file("data.bin", ios::app | ios::binary);
ifstream::pos_type size;
char * memblock;
int main () {
ifstream file ("data.bin", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
int c;
cout<<"read or write data? \n";
cin >> c;
if(c == "read"){
goto read;
}
else if(c == "write"){
goto write;
};
return 0;
else {
cin.get();
}
write:
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
char buffer[100];
ofstream file("data.bin", ios::app | ios::out | ios::binary);
file.write (buffer, 100);
file.close();
cout << "the complete file content is in memory";
delete[] memblock;
cin.get();
}
read:
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
cout << "the complete file content is in memory";
delete[] memblock;
cin.get();
}
else cout << "Unable to open file";
cin.get();
return 0;
}
Thanks in advance!!