Threads

vino via Digitalmars-d digitalmars-d at puremagic.com
Mon May 2 09:39:13 PDT 2016


Hi All,

  I am a newbie for D programming and need some help, I am trying 
to write a program using the example given in the book The "D 
Programming Language" written by "Andrei Alexandrescu" with few 
changes such as the example program read the input from stdin and 
prints the data to stdout, but my program reads the input from 
the file(readfile.txt) and writes the output to another 
file(writefile.txt), and I am getting the below errors while 
compiling

Error:

[root at localhost DProjects]# dmd readwriteb.d
readwriteb.d(7): Error: cannot implicitly convert expression 
(__aggr2859.front()) of type ubyte[] to immutable(ubyte)[]
readwriteb.d(15): Error: cannot implicitly convert expression 
(receiveOnly()) of type immutable(ubyte)[] to 
std.outbuffer.OutBuffer
[root at localhost DProjects]#

Version: DMD64 D Compiler v2.071.0

Code:

import std.algorithm, std.concurrency, std.stdio, std.outbuffer, 
std.file;

void main() {
    enum bufferSize = 1024 * 100;
    auto file = File("readfile.txt", "r");
    auto tid = spawn(&fileWriter);
    foreach (immutable(ubyte)[] buffer; file.byChunk(bufferSize)) {
       send(tid, buffer);
    }
}

void fileWriter() {
    auto wbuf  = new OutBuffer();
    for (;;) {
       wbuf = receiveOnly!(immutable(ubyte)[])();
       write("writefile.txt", wbuf);
    }
}

From,
Vino.B


More information about the Digitalmars-d mailing list