Any additions for write-to-file short program

pascal111 judas.the.messiah.111 at gmail.com
Fri Nov 19 23:32:17 UTC 2021


On Friday, 19 November 2021 at 23:05:03 UTC, H. S. Teoh wrote:
> On Fri, Nov 19, 2021 at 10:21:52PM +0000, pascal111 via 
> Digitalmars-d-learn wrote: [...]
>> When I compiled the code after adding yours, I found this 
>> error message:
>> 
>> "untitled20.d:24:8: error: no property 'copy' for type 
>> 'ByChunk'
>>    24 |        .copy(outputFile.lockingBinaryWriter); // copy 
>> each block
>> into output file
>>       |        ^
>> "
>
> import std.algorithm;
>
>
> T

Thanks! it works now.

code:

// D programming language

import std.stdio;
import std.string;
import std.algorithm;

int main()
{

string s;
char[] f;


try{
write("Enter file name and path: ");
readln(f);
f=strip(f);


File inputFile = File(f, "r");
File outputFile = File("output_x", "w");

enum bufferSize = 8194;
inputFile.byChunk(bufferSize)	// read input in blocks of 8194 
bytes
        .copy(outputFile.lockingBinaryWriter); // copy each block 
into output file


inputFile.close();
outputFile.close();
}


catch(Exception err){
stderr.writefln!"Warning! %s"(err.msg);
return 1;
}



return 0;

}


More information about the Digitalmars-d-learn mailing list