"Mike Austin" <mi**@mike-austin.com> schrieb im Newsbeitrag
news:Wx*********************@bgtnsc04-news.ops.worldnet.att.net...
It's the most annoying thing, and causes hours of frustration. Why
can't it
be resolved?
Regards,
Mike Austin
Example:
#include <iostream>
#include <fstream> here. #include <string>
using namespace std;
class DataStore {
public:
Store( string filename ) {
function declaration with no return type?
datafile.open( filename.c_str(), ios::in | ios::binary );
if( !_datafile ) {
'_datafile' is not declared. is it 'datafile' ?
if (datafile) will always return 'true', since datafile is a valid
object. Try datafile.is_open() here.
datafile.clear(); // Will not work correctly without clearing
// why not calling datafile.close() before re-opening it?
datafile.open( filename.c_str(), ios::out | ios::binary );
datafile.write( "what the?", 9 );
}
datafile.close();
datafile.open( filename.c_str(), ios::in | ios::out |
ios::binary );
Here, a '}' is missing.
private:
fstream datafile;
};
corrected code:
#include <fstream>
#include <string>
using namespace std;
class DataStore
{
public:
void Store( string filename )
{
datafile.open( filename.c_str(), ios::in | ios::binary );
if(!datafile.is_open())
{
datafile.clear(); // Will not work correctly without clearing
datafile.open( filename.c_str(), ios::out | ios::binary );
datafile.write( "what the?", 9 );
}
datafile.close();
datafile.open( filename.c_str(), ios::in | ios::out | ios::binary );
}
private:
fstream datafile;
};
HTH,
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com