Thanks again for taking the time to look my work.
Is the cerr error the very first one on the list?
Yes.
I created a project using the following code (copied from an online tutorial) and it works fine, does exactly what it should.
Code:
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
So I'm guessing my installation is fine and there must be something different about my code that's giving me problems.
I copied a lot more of my code below. I copied the #includes and declarations exactly as they appear, a small section on debugging (don't understand, thought it could be relevant), and the portion of code that I'm working on. Using the "Visual C++.NET Bible", I added a different method of file i/o (METHOD1)for which my project compiles. But when I debug it, I get an assertion error in a file called afxole.inl at line 166. (Everything within the 2 "test//test//test" comments is code added by me, otherwise, it was part of the original program)
Code:
// FSWinView.cpp : implementation of the CFSWinView class
//
///////////////////////
//// TEST // TEST /////
#include <iostream>///
#include <fstream>///
using namespace std;///
//// TEST // TEST /////
///////////////////////
#include "stdafx.h"
#include "FSWin.h"
#include "camera.h"
#include "FSWinDoc.h"
#include "FSWinView.h"
#include "FPFDlg.h"
#include "fpfimg.h"
#include "AlarmSettings.h"
#include ".\fswinview.h"
...
...
...
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
...
...
...
#ifdef _DEBUG
void CFSWinView::AssertValid() const
{
CFormView::AssertValid();
}
void CFSWinView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CFSWinDoc* CFSWinView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFSWinDoc)));
return (CFSWinDoc*)m_pDocument;
}
#endif //_DEBUG
...
...
...
int CFSWinView::ShowImage(int nImageType)
{
VARIANT va = m_Camera.GetImage(nImageType);
// Check validity of returned image
VARTYPE vt = (nImageType < 2 ? VT_I2 : (nImageType < 4 ? VT_R4 : VT_UI1));
if (va.vt == VT_I2) // Error
return (int)va.iVal;
if (va.vt != (VT_ARRAY | vt))
return -1;
COleSafeArray sa;
sa.Attach(va);
//////////////////////////////////////////////////////////////////////
////// TEST /// TEST /// TEST /// TEST /// TEST /// TEST /// TEST ////////////////////////
// Display dimensions of the array stored in "sa".
long w, h;
CString s, msg, table;
s.Format(_T("Dimensions: %d\n"), sa.GetDim());
msg += s;
sa.GetUBound(1, &w);
sa.GetUBound(2, &h);
w++;
h++;
s.Format(_T("Width of array: %ld\n"), w);
msg += s;
s.Format(_T("Height of array: %ld\n"), h);
msg += s;
AfxMessageBox(msg);
// 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;
}
////////////////////// NEW STUFF /////////////////////// (I got this from the "Visual C++ .NET Bible)
// Display contents of "table" in a text file. (Method 1)
HANDLE hFile = ::CreateFile("example.txt",
GENERIC_READ,
FILE_SHARE_READ,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
HANDLE pFile; //pFile was not defined in the Bible's example, so I added this.
if (hFile)
{
CFile file(hFile);
if (file.Open("example.txt", CFile::modeWrite))
{
try
{
file.SeekToEnd(); // Go to end of file so as to not overwrite existing data.
file.Write(table, strlen(table));
file.Close();
}
catch(CFileException* pe)
{
pe->ReportError();
if (pFile)
{
delete pFile;
}
}
}
}
///////////////////// END OF NEW STUFF //////////////////////
/* // Display contents of "table" in a text file. (Method 2)
ofstream outfile;
char filename[] = "c:/example.txt";
outfile.open(filename, ios::out);
if (!outfile) // Test file open.
{
cerr << "Can't open output file " << filename << endl;
return;
}
outfile << table << endl;
outfile.close();
*/
///// TEST /// TEST /// TEST /// TEST /// TEST /// TEST /// TEST ////////////////////////
//////////////////////////////////////////////////////////////////////
DisplayImage(nImageType, sa);
VariantClear(&va);
return 0;
}