Problem with file IO

This is a discussion on Problem with file IO within the C++ Programming forums, part of the General Programming Boards category; Sorry, one last thing, there is nothing between #include ".\fswinview.h" and #ifdef _DEBUG. I added the ... by mistake....

  1. #16
    Registered User
    Join Date
    Aug 2006
    Posts
    13
    Sorry, one last thing, there is nothing between #include ".\fswinview.h" and #ifdef _DEBUG. I added the ... by mistake.

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The stdafx.h header shows the problem. The compiler ignores everything that comes before that include directive. Remove it and turn off precompiled headers in the project options.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Registered User
    Join Date
    Aug 2006
    Posts
    13
    It now looks like this:
    Code:
    // FSWinView.cpp : implementation of the CFSWinView class
    //
    #include "stdafx.h"
    #include "FSWin.h"
    ///////////////////////
    //// TEST // TEST /////
    #include <iostream> ///
    #include <fstream>  ///
    using namespace std;///
    //// TEST // TEST /////
    ///////////////////////
    #include "camera.h"
    #include "FSWinDoc.h"
    ...
    That fixed the compiling, awesome! I didn't need to remove the #include "stdafx.h" or turn off precompiled headers. Thanks CornedBee. But I still get the assertion error during debugging. The problem is caused by something in this section:
    Code:
    // Display contents of "sa" (array of Kelvin temperature values) in the CString object "table".
    	float HUGEP *a_image;
    	sa.AccessData((void HUGEP **)&a_image);
    	for (int x=0 ; x<10 ; x++) // x<10 should be x<w
    	{
    		for (int y=0 ; y<10 ; y++) // y<10 should be y<h
    		{
    			s.Format("%4.2f  ", a_image[w*x+y]);
    			table += s;
    		}
    		s.Format(_T("\n"));
    		table += s;
    	}
    Any ideas?

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Get rid of the HUGEP thing. It's a relict from 16-bit Windows. But that's not the actual problem, so what type is sa? Are you sure the loop limits are correct? (The comments hint at a possible problem.) What's the value of w - it is used in the array access, but not in the loop itself, which is a bit weird. Which line exactly causes the assertion? The debugger should be able to tell you that, and also exactly what invalid value (typically) caused it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    Registered User
    Join Date
    Aug 2006
    Posts
    13
    "sa" is defined earlier as a COleSafeArray object. It can be seen in the code I posted on page 2 of this thread, and below. Note: "va" is an array of floating point values.
    Code:
    COleSafeArray sa;
    	sa.Attach(va);
    I'm pretty sure my loop limits are correct. While I was testing with AfxMessageBox, I set the loops to only display a portion of the array. I added those comments so that I would remember to eventually change them back. Below shows how w and h are defined. When executed, w= 320 and h=240.
    Code:
    long w, h;
    	... ... ...
    	sa.GetUBound(1, &w);
    	sa.GetUBound(2, &h);
    	w++;
    	h++;
    The exact error message I get is:
    Microsoft Visual C++ Debug Library

    Debug Assertion Failed!

    Program: ...tor\My Documents\Working Copies\Copy of FSWin\Debug\FSWin.exe
    File: f:\vs70builds\3077\vc\MFCATL\ship\atlmfc\include\a fxole.inl
    Line: 166

    For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

    (Press Retry to debug the application)
    If the debugger tells me more, I don't know where to find it.

  6. #21
    Registered User
    Join Date
    Aug 2006
    Posts
    13
    I'm a huge dope. I fixed it. I was using the COleSafeArray member "AccessData" without subsequently using "UnaccessData". Once I added that to my code, I was no longer getting the failed assertion.

    Thanks for all your help!
    Kind regards,
    Chunky

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Problem reading file
    By coder_009 in forum C Programming
    Replies: 10
    Last Post: 01-15-2008, 12:22 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. Totally puzzling IO problem
    By Vorok in forum C++ Programming
    Replies: 5
    Last Post: 01-06-2003, 06:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21