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 really don't know what you mean. Do you want to save integers to file? Binder?

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.

commented: thx for the link and code +1

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));
commented: Perfect +1
commented: Thanks +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.