Hypercell ein ] Hypercell aus ] Zeige Navigation ] Verstecke Navigation ]
c++.de  
   
Forentreff 2012     
Bücher-Shop mit Amazon (Buchkategorien)C++ : Referenzen zu C++ : C++ Builder : Visual C++ : C# : Java : Spieleprogrammierung : Systemprogrammierung Linux : Software-Entwicklung : .NET : Compilertechnik : Algorithmen & Datenstrukturen : Objektorientierung : Entwurfsmuster : UML : eXtreme Programming : Scrum : Projektmanagement : Software-Testing : Datenbanken : Tom DeMarco : Dilbert : User Friendly
C/C++ Forum :: Andere GUIs - Qt, GTK+, wxWidgets ::  std::fstream braucht zwei Anläufe um eine Datei zu erzeugen?     Zeige alle Beiträge auf einer Seite Auf Beitrag antworten
Autor Nachricht
FrankTheFox
Mitglied

Benutzerprofil
Anmeldungsdatum: 25.02.2007
Beiträge: 201
Beitrag 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
Beitrag Hacker Mitglied 23:20:17 19.01.2012   Titel:              Zitieren

Wurde (wenn ich dein Problem verstanden habe :D ) hier schon beantwortet.
FrankTheFox
Mitglied

Benutzerprofil
Anmeldungsdatum: 25.02.2007
Beiträge: 201
Beitrag FrankTheFox Mitglied 08:25:09 20.01.2012   Titel:              Zitieren

Hi,

ja, genau. Danke! :live:

Gruß

_________________
Im void dahoam!
C/C++ Forum :: Andere GUIs - Qt, GTK+, wxWidgets ::  std::fstream braucht zwei Anläufe um eine Datei zu erzeugen?   Auf Beitrag antworten

Zeige alle Beiträge auf einer Seite




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.

Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme

c++.de ist Teilnehmer des Partnerprogramms von Amazon Europe S.à.r.l. und Partner des Werbeprogramms, das zur Bereitstellung eines Mediums für Websites konzipiert wurde, mittels dessen durch die Platzierung von Werbeanzeigen und Links zu amazon.de Werbekostenerstattung verdient werden kann.

Die Vervielfältigung der auf den Seiten www.c-plusplus.de, www.c-plusplus.info, www.c-sar.de, www.c-plusplus.net und www.baeckmann.de enthaltenen Informationen ohne eine schriftliche Genehmigung des Seitenbetreibers ist untersagt (vgl. §4 Urheberrechtsgesetz). Die Nutzung und Änderung der vorgestellten Strukturen und Verfahren in privaten und kommerziellen Softwareanwendungen ist ausdrücklich erlaubt, soweit keine Rechte Dritter verletzt werden. Der Seitenbetreiber übernimmt keine Gewähr für die Funktion einzelner Beiträge oder Programmfragmente, insbesondere übernimmt er keine Haftung für eventuelle aus dem Gebrauch entstehenden Folgeschäden.