G
Guest
Hello
I'm a self instructed amateur attempting to read a huge file from disk... so
bear with me please... I just learned that reading a file in binary is
faster than text. So I wrote the following code that compiles OK. It runs and
shows the requested output. However, after execution, it pops one of those
windows to send error reports online to the porgram creator. I have managed
to find where the error is but can't see what's wrong. I'm posting the whole
code for context. I'm also marking where the problem is.
I appreciate your assistance. Thanks
#include <fstream>
#include <iostream>
#include <map>
using namespace std;
int main()
{
typedef map<int, double> IMAP;
IMAP Grid, NewGrid;
int IntValue1, rows = 3;
double DouValue2;
for(int i=0; i < rows; i++)
{
IntValue1 = i + 1;
DouValue2 = i * 2;
Grid.insert(IMAP::value_type(IntValue1, DouValue2));
}
IMAP::const_iterator IteratorG = Grid.begin();
cout << "Original Map" << endl;
while (IteratorG != Grid.end() )
{
cout << IteratorG->first << " " << IteratorG->second << endl;
IteratorG ++;
}
ofstream FileOut("C:/MyBinary.bin" , ios::binary);
FileOut.write((char*) &Grid, sizeof Grid);
FileOut.close();
// ******** PROBLEM IN HERE ******************
ifstream FileIn("C:/MyBinary.bin", ios::binary);
FileIn.read((char*) &NewGrid,sizeof NewGrid);
FileIn.close();
// *****************************************
IMAP::const_iterator NewIteratorG = NewGrid.begin();
cout << " " << endl;
cout << "New Map" << endl;
while (NewIteratorG != NewGrid.end() )
{
cout << NewIteratorG->first << " " << NewIteratorG->second << endl;
NewIteratorG ++;
}
return 0;
}
I'm a self instructed amateur attempting to read a huge file from disk... so
bear with me please... I just learned that reading a file in binary is
faster than text. So I wrote the following code that compiles OK. It runs and
shows the requested output. However, after execution, it pops one of those
windows to send error reports online to the porgram creator. I have managed
to find where the error is but can't see what's wrong. I'm posting the whole
code for context. I'm also marking where the problem is.
I appreciate your assistance. Thanks
#include <fstream>
#include <iostream>
#include <map>
using namespace std;
int main()
{
typedef map<int, double> IMAP;
IMAP Grid, NewGrid;
int IntValue1, rows = 3;
double DouValue2;
for(int i=0; i < rows; i++)
{
IntValue1 = i + 1;
DouValue2 = i * 2;
Grid.insert(IMAP::value_type(IntValue1, DouValue2));
}
IMAP::const_iterator IteratorG = Grid.begin();
cout << "Original Map" << endl;
while (IteratorG != Grid.end() )
{
cout << IteratorG->first << " " << IteratorG->second << endl;
IteratorG ++;
}
ofstream FileOut("C:/MyBinary.bin" , ios::binary);
FileOut.write((char*) &Grid, sizeof Grid);
FileOut.close();
// ******** PROBLEM IN HERE ******************
ifstream FileIn("C:/MyBinary.bin", ios::binary);
FileIn.read((char*) &NewGrid,sizeof NewGrid);
FileIn.close();
// *****************************************
IMAP::const_iterator NewIteratorG = NewGrid.begin();
cout << " " << endl;
cout << "New Map" << endl;
while (NewIteratorG != NewGrid.end() )
{
cout << NewIteratorG->first << " " << NewIteratorG->second << endl;
NewIteratorG ++;
}
return 0;
}