hi
i need to write some hex data into a binary file block by block and read it back same as block by block
i try to do it but some error i don't no how to fix this i am stuck i all kind of help appreciated thank u
]Code:#include <iostream> #include <fstream> #include <string> using namespace std; int main() { string block1 = "DEDEDEDEDEDEDEDEDEDEDED"; // hex data string block2 = "AFAFAFAFAFAFAFAFAFA"; // hex data string block3= "BFBFBFBFBFBFBFBFBFBBFBF"; // hex data string outBlock1; string outBlock2; string outBlock1; fstream file("example.bin", ios::binary | ios::in |ios::out | ios::trunc); if (!file.is_open()){ cout << "error"; } else { file.write((char *)&block1, sizeof(block1)); file.write((char *)&block2, sizeof(block2)); file.write((char *)&block3, sizeof(block3)); file.read((char *)&indata, sizeof(indata)); /* cout << indata << endl;*/ } file.close(); return 0; }




Reply With Quote
