Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

istream::getline

Status
Not open for further replies.

pfildes

Programmer
Jun 17, 2004
54
GB
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 [smile], but it hangs on the first call to the getline function [sad] - see code below;

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top