0

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...

4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Jx_Man
Featured Replies
  • 1
    Duoas 1,025   9 Years Ago

    [URL="http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html"]Link[/URL]. 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 [B]int[/B] instead of [B]Data[/B]. [code=C++] #include <fstream.h> ... int x; int *y = new int[10]; fstream myFile ("data.bin", ios::in | ios::out | ios::binary); … Read More

  • 2

    this following code to save int file into DAT file : [CODE]# 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], … Read More

0

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.

1

Link.

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.

Comments
thx for the link and code
2

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));
	file_data.close();
}
Comments
Thanks
Perfect
This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.