I have recently converted a C++ program to a MFC DLL and am having problems with istream::getline function. It opens the file (sufficed .sac) no problem , but it hangs on the first call to the getline function - see code below;
I am kinda new to C++ programming. I've inherited this code which did work when compiled as a program. Any suggestions would be very much appreciated!!!.
Paul
Code:
#include <iostream.h>
#include <strstrea.h>
#include "beam.h"
#include "stdafx.h"
ConcreteBeam::ConcreteBeam(const char* theBeamModel, short& theStatus)
{
RWCString aModelName(theBeamModel);
int aDotPos;
if ((aDotPos=aModelName.index(".sac")) == RW_NPOS)
aModelName += ".sac";
AfxMessageBox(aModelName,MB_APPLMODAL|MB_ICONINFORMATION);
//open input file
ifstream anInputFileStream;
anInputFileStream.clear();
anInputFileStream.open(aModelName);
AfxMessageBox("File Opened",MB_APPLMODAL|MB_ICONINFORMATION);
if (anInputFileStream.fail())
theStatus=1;
else
{AfxMessageBox("Reading....",MB_APPLMODAL|MB_ICONINFORMATION);
anInputFileStream >> *this;
theStatus=0;}
}
istream& operator >> (istream& theStream, ConcreteBeam& theData)
{
char aBuf[129] = {0};
if(!theStream.good() == 1) {
AfxMessageBox("The file stream is not a good one.\nCannot continue with this file",
MB_APPLMODAL|MB_ICONSTOP);
theStream.clear(2);
return theStream;
}
AfxMessageBox("Reading 1st line..",MB_APPLMODAL|MB_ICONINFORMATION);
[b]theStream.getline(aBuf, 128, (char)'\n');[/b] //Saccom Magic Number
AfxMessageBox("Done!",MB_APPLMODAL|MB_ICONINFORMATION);
if (strcmp(aBuf, "#MSC-STR-SACCOM-1.0") != 0) {
theStream.clear(2);
AfxMessageBox("This is not a valid SACCOM data file.\nThe program identity string is missing",
MB_APPLMODAL|MB_ICONSTOP);
return theStream;
}
AfxMessageBox("Reading [BeamInfo]",MB_APPLMODAL|MB_ICONINFORMATION);
theStream.getline(aBuf, 128, (char)'\n'); //BeamInfo Header
AfxMessageBox("Reading BeamID",MB_APPLMODAL|MB_ICONINFORMATION);
theStream.getline(aBuf, 128, (char)'\n'); //BeamID
theData.GetBeamTitleRef()=aBuf;
return theStream;
}
I am kinda new to C++ programming. I've inherited this code which did work when compiled as a program. Any suggestions would be very much appreciated!!!.
Paul