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!

Assertion failing when I write to ofstream& in function

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hi.
I have a function that looks exactly like this:

void Tga_string::write_to_file(ofstream& file)
{
if(file.is_open()){
for(u_int indx(0);indx<Fcommands.size();indx++)
file<<Fcommands[indx]->command_string().c_str()<<endl;
file<<&quot;//END\n\n&quot;;
}
else
throw Efile_nopen(&quot;ga string file&quot;);
}

The trouble is, whenever I call it, I get a wierd message saying:
Assertion failed: !&quot;bogus context in _ExceptionHandler()&quot;, file xx.cpp, line 3071


Then I get an abnormal program termination to OK, & then I am bounced to the CPU box, which is WAY out of my league.
I can create the file & write to it in the main body of my code, so why won't it work here?
The line it falls over on is:
file<<Fcommands[indx]->command_string().c_str()<<endl;


All other functions checked out here are fine - the command_string() function simply returns an STL string & checks out OK.
Can anybody offer any help?
I'm deeply baffled!
Cheers,
DJL

Common sense is what tells you the world is flat.
 
I've altered the function so that it now reads:

void Tga_string::write_to_file(ofstream& file)
{
if(file.is_open()){
string line;
for(u_int indx(0);indx<Fcommands.size();indx++){
line=Fcommands[indx]->command_string();
file<<line.c_str();
file<<endl;
}//next indx
file<<&quot;//END\n\n&quot;;
}
else
throw Efile_nopen(&quot;ga string file&quot;);
}

Now the file just gets filled with '\n' characters for the number of iterations of indx.
I am SERIOUSLY confused!
I hate to say it, but this is looking like a BCB6 bug somewhere.
Anyone any ideas what might be going wrong?
Or how to fix it?
Cheers,
DJL

Common sense is what tells you the world is flat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top