std::fstream braucht zwei Anläufe um eine Datei zu erzeugen?
-
Hallo,
ich mache folgendes:
in meiner App.h
std::fstream *MonitorFile1; std::fstream *MonitorFile2; std::fstream *DataFile1; std::fstream *DataFile2;
in der App.cpp
IMPLEMENT_APP(wxMyApp); bool wxMyApp::OnInit() { ... GetAppPath( DataFilePath ); DataFilePath.Append( _("/DataFolder/") ); if ( !::wxDirExists( DataFilePath ) ) { wxFileName oFN( DataFilePath ); oFN.Mkdir( 0777 ); } DataFile1 = new std::fstream(); DataFile2 = new std::fstream(); DataFile1->open( wxString::Format( wxT("%ParamsStuff1.txt"), DataFilePath.c_str() ).mbc_str() ); if ( !DataFile1->is_open() ) { DataFile1->open( wxString::Format( wxT("%ParamsStuff1.txt"), DataFilePath.c_str() ).mbc_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc ); if( !DataFile1->open() ) { delete DataFile1; DataFile1 = NULL; } } DataFile2->open( wxString::Format( wxT("%ParamsStuff2.txt"), DataFilePath.c_str() ).mbc_str() ); if ( !DataFile2->is_open() ) { DataFile2->open( wxString::Format( wxT("%ParamsStuff2.txt"), DataFilePath.c_str() ).mbc_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc ); if( !DataFile2->open() ) { delete DataFile2; DataFile2 = NULL; } } ... int wxMyApp::OnExit() { if( DataFile1) { DataFile1->close(); delete DataFile1; } if(DataFile2) { DataFile2->close(); delete DataFile2; } ... }
Wieso muss ich open 2x aufrufen und warum wird die Datei beim ersten Mal nicht erzeugt?
-
Wurde (wenn ich dein Problem verstanden habe
) hier schon beantwortet.
-
Hi,
ja, genau. Danke!
Gruß