Autor
Nachricht
FrankTheFox
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.02.2007
Beiträge: 201
FrankTheFox Mitglied
18:37:43 19.01.2012 Titel:
std::fstream braucht zwei Anläufe um eine Datei zu erzeugen?
Zitieren
Hallo,
ich mache folgendes:
in meiner App.h
C/C++ Code: std::fstream *MonitorFile1;
std::fstream *MonitorFile2;
std::fstream *DataFile1;
std::fstream *DataFile2;
C/C++ Code: std::fstream *MonitorFile1;
std::fstream *MonitorFile2;
std::fstream *DataFile1;
std::fstream *DataFile2;
C/C++ Code: std::fstream *MonitorFile1;
std::fstream *MonitorFile2;
std::fstream *DataFile1;
std::fstream *DataFile2;
in der App.cpp
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
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;
}
...
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
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;
}
...
}
C/C++ Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
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?
_________________ Im void dahoam!
Hacker
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.04.2011
Beiträge: 1855
Hacker Mitglied
23:20:17 19.01.2012 Titel:
Zitieren
Wurde (wenn ich dein Problem verstanden habe ) hier schon beantwortet.
FrankTheFox
Mitglied
Benutzerprofil
Anmeldungsdatum: 25.02.2007
Beiträge: 201
FrankTheFox Mitglied
08:25:09 20.01.2012 Titel:
Zitieren
Hi,
ja, genau. Danke!
Gruß
_________________ Im void dahoam!
Nächstes Thema anzeigen
Vorheriges Thema anzeigen
Sie können Beiträge in dieses Forum schreiben. Sie können auf Beiträge in diesem Forum antworten. Sie können Ihre Beiträge in diesem Forum nicht bearbeiten. Sie können Ihre Beiträge in diesem Forum nicht löschen. Sie können an Umfragen in diesem Forum nicht mitmachen.