www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to append a new line to a File/FileConduit?

reply Sam Hu <samhu.samhu gmail.com> writes:
Hello everyone!

Just found I can not append a new line to a file when writing data to a File or
FileConduit instance.

File file=new File("myfile.txt");
myfile.append("This is line 1");
myfile.append("This is line 2");
About code just generate "This is line 1This is line 2"
I tried below code but all the same:
myfile.append("\n\nThis is line 1\n\n");
myfile.append("\n");
myfile.append("This is line 2");

Can anybody help my on how to make it ?I just want to write data into a file
line by line:
This is line 1
This is line 2

Thanks.

Sam
Jan 12 2009
parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Tue, Jan 13, 2009 at 1:42 AM, Sam Hu <samhu.samhu gmail.com> wrote:
 Hello everyone!

 Just found I can not append a new line to a file when writing data to a File
or FileConduit instance.

 File file=new File("myfile.txt");
 myfile.append("This is line 1");
 myfile.append("This is line 2");
 About code just generate "This is line 1This is line 2"
 I tried below code but all the same:
 myfile.append("\n\nThis is line 1\n\n");
 myfile.append("\n");
 myfile.append("This is line 2");
If you're on Windows, the line ending convention is "\r\n", not just "\n", so you could try that. Alternatively, use a Print/FormatOutput (depends on whether you're using 0.99.7 or HEAD).
Jan 13 2009
parent Sam Hu <samhu.samhu gmail.com> writes:
Thanks.It works now.

Regards,
Sam
Jan 13 2009