www.digitalmars.com         C & C++   DMDScript  

D - Help anyone?

reply "Andrew Edwards" <crxace13 comcast.net> writes:
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

the following code:

import stream;
import file;
int main (char[][] args)
{
   File file = new File;
   file.create("test.txt");
   int a = 0, b = 1;
   for (int i = 0; i < 1000; i++)
   {
      int c = a + b;
      file.write(c);
      a = b; b = c;
   }
   return 0;
}

generates the attached file.  Does this happen to anyone except me?

Thanks in advance,
Andrew
Sep 12 2002
parent reply Pavel Minayev <evilone omen.ru> writes:
Andrew Edwards wrote:
 the following code:
 
 import stream;
 import file;
 int main (char[][] args)
 {
    File file = new File;
    file.create("test.txt");
    int a = 0, b = 1;
    for (int i = 0; i < 1000; i++)
    {
       int c = a + b;
       file.write(c);
       a = b; b = c;
    }
    return 0;
 }
 
 generates the attached file.  Does this happen to anyone except me?

Yes, it is supposed to work that way. Unlike C++ iostreams, Stream.write() saves data as binary, not as text. If you nead to read/write text files, use Stream.printf() and Stream.scanf(). By the way, there is no need to import file.d in your program. stream.d would be enough.
Sep 12 2002
parent "Andrew Edwards" <crxace13 comcast.net> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:alrsvt$gvj$1 digitaldaemon.com...

| By the way, there is no need to import file.d in your program. stream.d
| would be enough.

That was my next question! Thank you very much!
Sep 13 2002