hi all,
i m new in this forums.
i want to save int file into dat in according to biner. please help me cause i dont know how to start..

thx.. best regards...

i mean that i want to record some data from array to Dat File (ex int.DAT) and the type of file is integer.
ok.please help me i really confused.


Pay special attention to the section on "Reading and Writing Complex Data". You are interested in integers, but the same principles apply. Here's their example using int instead of Data.

#include <fstream.h>
    int x;
    int *y = new int[10];

    fstream myFile ("data.bin", ios::in | ios::out | ios::binary);
    myFile.seekp (location1);
    myFile.write ((char*)&x, sizeof (int));
    myFile.seekg (0);
    myFile.read ((char*)y, sizeof (int) * 10);

Good luck.

thx for the link and code

this following code to save int file into DAT file :

# include <iostream.h>
# include <fstream.h>

void main ()
	int data[] = { 23, 456, 678, 2314, 20, 56, 30981};
	cout<< "Record Data...." <<endl;
	ofstream file_data("INT.DAT", ios::binary);
	for (int i = 0;i < (sizeof(data)/sizeof(int)); i++)
		file_data.write((char *) &data[i], sizeof(int));
This question has already been answered. Start a new discussion instead.