Click here to Skip to main content
15,921,793 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: HDC and CStatic control question Pin
Steve Messer1-Jun-05 7:38
Steve Messer1-Jun-05 7:38 
GeneralRe: HDC and CStatic control question Pin
Ryan Binns1-Jun-05 18:25
Ryan Binns1-Jun-05 18:25 
GeneralRe: HDC and CStatic control question Pin
Steve Messer13-Jun-05 20:38
Steve Messer13-Jun-05 20:38 
Generalworking with binary files in C++ Pin
knapak1-Jun-05 5:55
knapak1-Jun-05 5:55 
GeneralRe: working with binary files in C++ Pin
David Crow1-Jun-05 7:07
David Crow1-Jun-05 7:07 
GeneralRe: working with binary files in C++ Pin
knapak1-Jun-05 8:21
knapak1-Jun-05 8:21 
GeneralRe: working with binary files in C++ Pin
S. Senthil Kumar1-Jun-05 8:33
S. Senthil Kumar1-Jun-05 8:33 
GeneralRe: working with binary files in C++ Pin
knapak1-Jun-05 9:23
knapak1-Jun-05 9:23 
OK... so I wrote the following code and it writes and reads the file with a map. It compiles, runs and gives the requested output, but apparently there's a runtime problem since after execution a window pops indicating that there was a problem (one of those windows to send information to the creator of the program)... I can't see what's wrong but I know where the problem is since I commented different sections of the code and narrowed it down to the marked fragment below.

Here's the code:

int main()<br />
{<br />
	typedef map<int, double> IMAP;<br />
<br />
	IMAP Grid, NewGrid;<br />
<br />
	int IntValue1, rows = 3;<br />
	double DouValue2;<br />
<br />
	for(int i=0; i < rows; i++)<br />
	{<br />
		IntValue1 = i + 1;<br />
		DouValue2 = i * 2;<br />
		Grid.insert(IMAP::value_type(IntValue1, DouValue2));<br />
	}<br />
<br />
	IMAP::const_iterator IteratorG = Grid.begin();<br />
<br />
	cout << "Original Map" << endl;<br />
	while (IteratorG != Grid.end() )<br />
	{<br />
		cout << IteratorG->first << " " << IteratorG->second << endl;<br />
		IteratorG ++;<br />
	}<br />
<br />
	ofstream FileOut("C:/MyBinary.bin" , ios::binary);<br />
	FileOut.write((char*) &Grid, sizeof Grid);<br />
	FileOut.close();<br />


THE ERROR IS FROM HERE
ifstream FileIn("C:/MyBinary.bin", ios::binary);<br />
FileIn.read((char*) &NewGrid,sizeof NewGrid);<br />
FileIn.close();<br />


TO HERE

	IMAP::const_iterator NewIteratorG = NewGrid.begin();<br />
<br />
	cout << " " << endl;<br />
	cout << "New Map" << endl;<br />
	while (NewIteratorG != NewGrid.end() )<br />
	{<br />
		cout << NewIteratorG->first << " " << NewIteratorG->second << endl;<br />
		NewIteratorG ++;<br />
	}<br />
	return 0;<br />
}<br />



Thanks a million!
GeneralRe: working with binary files in C++ Pin
S. Senthil Kumar2-Jun-05 1:15
S. Senthil Kumar2-Jun-05 1:15 
GeneralRe: working with binary files in C++ Pin
knapak2-Jun-05 11:48
knapak2-Jun-05 11:48 
Generalusing library in different solution Pin
_indra_m1-Jun-05 5:49
_indra_m1-Jun-05 5:49 
GeneralMultiple files Pin
Andrew Admire1-Jun-05 4:35
Andrew Admire1-Jun-05 4:35 
GeneralRe: Multiple files Pin
M.Mehrdad.M1-Jun-05 5:48
M.Mehrdad.M1-Jun-05 5:48 
GeneralRe: Multiple files Pin
Andrew Admire1-Jun-05 6:32
Andrew Admire1-Jun-05 6:32 
GeneralRe: Multiple files Pin
David Crow1-Jun-05 7:32
David Crow1-Jun-05 7:32 
GeneralRe: Multiple files Pin
Andrew Admire1-Jun-05 8:07
Andrew Admire1-Jun-05 8:07 
GeneralRe: Multiple files Pin
David Crow1-Jun-05 8:16
David Crow1-Jun-05 8:16 
GeneralRe: Multiple files Pin
S. Senthil Kumar1-Jun-05 8:36
S. Senthil Kumar1-Jun-05 8:36 
GeneralRe: Multiple files Pin
Andrew Admire1-Jun-05 9:49
Andrew Admire1-Jun-05 9:49 
GeneralIE plugin Pin
Tender_Nail1-Jun-05 3:52
Tender_Nail1-Jun-05 3:52 
GeneralRe: IE plugin Pin
ThatsAlok1-Jun-05 18:20
ThatsAlok1-Jun-05 18:20 
GeneralSupported file types in DirectShow Pin
mssg1-Jun-05 2:37
mssg1-Jun-05 2:37 
GeneralRe: Supported file types in DirectShow Pin
Momotte1-Jun-05 2:41
Momotte1-Jun-05 2:41 
QuestionWhat happened to my CString? Pin
IlanTal1-Jun-05 1:50
IlanTal1-Jun-05 1:50 
GeneralMicrosoft Visual C++ Code Library: &quot;Buffer Overrun&quot; (link.exe) Pin
MahatmaG1-Jun-05 1:50
MahatmaG1-Jun-05 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.