 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Thomas Schindler Guest
|
Posted: Wed Apr 28, 2004 3:04 pm Post subject: iostream nocreate |
|
|
Hallo
#include <iostream>
std::ifstream f ("file1.txt"); // <- erzeugt leere Datei, wenn File
nicht existiert
Ich will ein File öffnen mit ifstream. Soweit so gut.
Wenn ich aber ein nicht existierendes Date öffne, erzeugt es eine leere
Datei,
was nicht erwünscht ist. Wie kann ich es in std-Manier verhindern?
Gruss, Thomas
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
news Guest
|
Posted: Wed Apr 28, 2004 9:06 pm Post subject: Re: iostream nocreate |
|
|
"Thomas Schindler" <thomas.schindler (AT) noname (DOT) ch> writes:
| Quote: | #include <iostream
std::ifstream f ("file1.txt"); // <- erzeugt leere Datei, wenn File
nicht existiert
|
Nein, das wird nicht mal übersetzt, wenn nicht
Und wenn <fstream> #included wird, wird die Datei *nicht* erzeugt, wenn sie
nicht schon existiert.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Martin Kaul Guest
|
Posted: Thu Apr 29, 2004 8:21 am Post subject: Re: iostream nocreate |
|
|
Thomas Schindler wrote:
| Quote: | Hallo
#include <iostream
std::ifstream f ("file1.txt"); // <- erzeugt leere Datei, wenn File
nicht existiert
|
Weder mit Borland C++-Builder 6 noch mit gcc (Version 3.3.1) kann
ich dein Problem nachvollziehen. Bei mir wird keine leere Datei erzeugt
Das einzige was ich brauchte war ein "#include
das duerfte nicht die Ursache sein.
tschaule
Martin
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Helmut Zeisel Guest
|
Posted: Thu Apr 29, 2004 8:23 am Post subject: Re: iostream nocreate |
|
|
Thomas Schindler wrote:
| Quote: | Hallo
#include
std::ifstream f ("file1.txt"); // <- erzeugt leere Datei, wenn File
nicht existiert
Ich will ein File öffnen mit ifstream. Soweit so gut.
Wenn ich aber ein nicht existierendes Date öffne, erzeugt es eine leere
Datei,
was nicht erwünscht ist. Wie kann ich es in std-Manier verhindern?
|
In den Standard Streamklassen wurden ios::nocreate und ios::noreplace
abgeschafft. Ich habe keine Ahnung, warum; mir fehlen sie auch,
insbesondere wenn ich alten Code auf ISO C++ umstellen will. Du musst
daher irgendeine passende Funktion aufrufen, um herauszufinden, ob die
Datei exisitiert.
Helmut
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Dietmar Kuehl Guest
|
Posted: Thu Apr 29, 2004 9:00 am Post subject: Re: iostream nocreate |
|
|
"Thomas Schindler" <thomas.schindler (AT) noname (DOT) ch> wrote:
| Quote: | #include <iostream
std::ifstream f ("file1.txt"); // <- erzeugt leere Datei, wenn File
nicht existiert
|
Laut Standard wird kein File erzeugt, wenn versucht wird, es read-only
zu öffnen.
| Quote: | Wenn ich aber ein nicht existierendes Date öffne, erzeugt es eine leere
Datei, was nicht erwünscht ist. Wie kann ich es in std-Manier verhindern?
|
Da Deine Implementierung offenbar nicht standard-konform ist und die
standard-konforme Methode, eine File zu öffnen ohne es zu erzeugen,
offenbar nicht funktioniert, kann Dir der Standard da wenig weiterhelfen.
Eine Variante wäre es natürlich, den aktuell verwendeten Compiler nach
/dev/null zu verschieben und durch einen eher konformen Compiler zu
ersetzen.
--
<http://www.contendix.com> - Software Development & Consulting
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Helmut Zeisel Guest
|
Posted: Thu Apr 29, 2004 9:07 am Post subject: Re: iostream nocreate |
|
|
Martin Kaul wrote:
| Quote: | Thomas Schindler wrote:
Hallo
#include
std::ifstream f ("file1.txt"); // <- erzeugt leere Datei, wenn
File
nicht existiert
Weder mit Borland C++-Builder 6 noch mit gcc (Version 3.3.1) kann
ich dein Problem nachvollziehen. Bei mir wird keine leere Datei erzeugt
|
Habe es gerade ueberprueft - der Effekt tritt bei mir auch nur bei
std::ofstream auf, nicht bei std::ifstream. Vor allem fehlt mir
ios::noreplace; ios::nocreate benötige ich selten.
Helmut
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Thomas Schindler Guest
|
Posted: Fri Apr 30, 2004 9:27 am Post subject: Re: iostream nocreate |
|
|
Danke für Antworten.
Ja, es sollte standartkonform sein, ist es aber auf MS VC 6.0 nicht. Grrr...
ok, habe mir mit der folgende Funktion aus der C-Bibliothek abgeholfen um zu
prüfen ob eine Datei existiert.
struct _finddata_t c_file;
_findfirst(baseFile.c_str(), &c_file ));
Gruss, Tom
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|