S
Squid Seven
I'm trying to use a pointer to an ofstream object and having problems:
ofstream *sessionFile = NULL;
if( directory == "" )
sessionFile = new ofstream( fileName.c_str(), ios:ut );
else
{
string fullFileName( directory );
fullFileName.append( fileName, 1, fileName.length() );
ofstream sessionFile( fullFileName.c_str(), ios:ut );
}
*sessionFile << deckFileName.c_str() << "~\n\n"
<< primaryRangeStart << "~\n"
<< primaryRangeLength << "~\n\n"
<< numberCardsTotal << "~\n\n";
for( int counter = 1; counter <= numberCardsTotal; counter++ )
*sessionFile << weights[ counter ] << "~\n";
The file is being created, but there's nothing in it! I've confirmed
that the if-contained line is being executed. If I change the code as
follows, it works just fine:
ofstream sessionFile( fileName.c_str(), ios:ut );
sessionFile << deckFileName.c_str() << "~\n\n"
<< primaryRangeStart << "~\n"
<< primaryRangeLength << "~\n\n"
<< numberCardsTotal << "~\n\n";
for( int counter = 1; counter <= numberCardsTotal; counter++ )
sessionFile << weights[ counter ] << "~\n";
What gives? How can I use the pointer to stream data into the ofstream
object?
ofstream *sessionFile = NULL;
if( directory == "" )
sessionFile = new ofstream( fileName.c_str(), ios:ut );
else
{
string fullFileName( directory );
fullFileName.append( fileName, 1, fileName.length() );
ofstream sessionFile( fullFileName.c_str(), ios:ut );
}
*sessionFile << deckFileName.c_str() << "~\n\n"
<< primaryRangeStart << "~\n"
<< primaryRangeLength << "~\n\n"
<< numberCardsTotal << "~\n\n";
for( int counter = 1; counter <= numberCardsTotal; counter++ )
*sessionFile << weights[ counter ] << "~\n";
The file is being created, but there's nothing in it! I've confirmed
that the if-contained line is being executed. If I change the code as
follows, it works just fine:
ofstream sessionFile( fileName.c_str(), ios:ut );
sessionFile << deckFileName.c_str() << "~\n\n"
<< primaryRangeStart << "~\n"
<< primaryRangeLength << "~\n\n"
<< numberCardsTotal << "~\n\n";
for( int counter = 1; counter <= numberCardsTotal; counter++ )
sessionFile << weights[ counter ] << "~\n";
What gives? How can I use the pointer to stream data into the ofstream
object?