Thread overview
append line with stream on file
Apr 20, 2004
Manfred Hansen
Apr 20, 2004
Matthew
Apr 20, 2004
Andrew
Apr 20, 2004
Andrew
Apr 20, 2004
Ben Hinkle
Apr 20, 2004
Andrew Edwards
Apr 20, 2004
Kris
April 20, 2004
Hello,

is it possible to append a line on a file with std.streams ?

import std.stream;

int main() {
        File file = new File;
        file.create("testfile.txt");

        file.writeLine("Line 1");

        file.close();

        return 0;
}


If i run the programm twice, i have only one line in my file.

In C looks like:

#include <stdio.h>

int main(void) {

        FILE* fp;
        fp= fopen("testfile.txt","a+");
        fputs("Line 1",fp);
        fclose(fp);

        return 0;
}


I missed an append function in stream's .

Manfred
April 20, 2004
Shouldn't you use an open() method? (I don't know; just guessing)

"Manfred Hansen" <manfred@toppoint.de> wrote in message news:c63r3p$btu$1@digitaldaemon.com...
> Hello,
>
> is it possible to append a line on a file with std.streams ?
>
> import std.stream;
>
> int main() {
>         File file = new File;
>         file.create("testfile.txt");
>
>         file.writeLine("Line 1");
>
>         file.close();
>
>         return 0;
> }
>
>
> If i run the programm twice, i have only one line in my file.
>
> In C looks like:
>
> #include <stdio.h>
>
> int main(void) {
>
>         FILE* fp;
>         fp= fopen("testfile.txt","a+");
>         fputs("Line 1",fp);
>         fclose(fp);
>
>         return 0;
> }
>
>
> I missed an append function in stream's .
>
> Manfred


April 20, 2004
In article <c63r3p$btu$1@digitaldaemon.com>, Manfred Hansen says...
>
>Hello,
>
>is it possible to append a line on a file with std.streams ?
>
>import std.stream;
> 
>int main() {
>        File file = new File;
>        file.create("testfile.txt");
> 

Replaceing your first two lines with:

File file = new File("testfile.txt",FileMode.Out);
file.seekEnd(0);

Should do the trick!

>        file.writeLine("Line 1");
> 
>        file.close();
> 
>        return 0;
>}
>
>
>If i run the programm twice, i have only one line in my file.
>
>In C looks like:
>
>#include <stdio.h>
> 
>int main(void) {
> 
>        FILE* fp;
>        fp= fopen("testfile.txt","a+");
>        fputs("Line 1",fp);
>        fclose(fp);
> 
>        return 0;
>}
>
>
>I missed an append function in stream's .
>
>Manfred


April 20, 2004
In article <c64039$kmq$1@digitaldaemon.com>, Andrew says...
>
>In article <c63r3p$btu$1@digitaldaemon.com>, Manfred Hansen says...
>>
>>Hello,
>>
>>is it possible to append a line on a file with std.streams ?
>>
>>import std.stream;
>> 
>>int main() {
>>        File file = new File;
>>        file.create("testfile.txt");
>> 
>
>Replaceing your first two lines with:
>
>File file = new File("testfile.txt",FileMode.Out);
>file.seekEnd(0);
>
>Should do the trick!
>

Even Better:

File file = new File;
try {
file.open("testfile.txt",FileMode.Out);
} catch (OpenError e) {
file.create("testfile.txt",FileMode.Out);
}
file.seekEnd(0);


April 20, 2004
> Even Better:
>
> File file = new File;
> try {
> file.open("testfile.txt",FileMode.Out);
> } catch (OpenError e) {
> file.create("testfile.txt",FileMode.Out);
> }
> file.seekEnd(0);

My std.stream "update" fixes that bug. File open will create if it isn't there.

-Ben


April 20, 2004
Must be in 0.82, I'm still stuck on 0.81 and tried it after I made my first post. Needless to say: it didn't work. I'll download 0.82. Thanks...

"Ben Hinkle" <bhinkle4@juno.com> wrote in message news:c643e8$q1c$1@digitaldaemon.com...
>
> > Even Better:
> >
> > File file = new File;
> > try {
> > file.open("testfile.txt",FileMode.Out);
> > } catch (OpenError e) {
> > file.create("testfile.txt",FileMode.Out);
> > }
> > file.seekEnd(0);
>
> My std.stream "update" fixes that bug. File open will create if it isn't there.
>
> -Ben
>
>


April 20, 2004
Andrew,

Ben was talking about his *updated* version: it's not in the Phobos library (yet). Ben provided a download link for it a week or so ago, and I think this is probably the place: http://home.comcast.net/~benhinkle/stream.d

- Kris

"Andrew Edwards" <edwardsac@spamfreeusa.com> wrote in message news:c645op$u1q$1@digitaldaemon.com...
> Must be in 0.82, I'm still stuck on 0.81 and tried it after I made my
first
> post. Needless to say: it didn't work. I'll download 0.82. Thanks...
>
> "Ben Hinkle" <bhinkle4@juno.com> wrote in message news:c643e8$q1c$1@digitaldaemon.com...
> >
> > > Even Better:
> > >
> > > File file = new File;
> > > try {
> > > file.open("testfile.txt",FileMode.Out);
> > > } catch (OpenError e) {
> > > file.create("testfile.txt",FileMode.Out);
> > > }
> > > file.seekEnd(0);
> >
> > My std.stream "update" fixes that bug. File open will create if it isn't there.
> >
> > -Ben
> >
> >
>
>