Just an example, why D rocks, and C++ s***s...

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Mar 16 12:18:15 UTC 2022


On Wednesday, 16 March 2022 at 11:20:45 UTC, user1234 wrote:
> On Wednesday, 16 March 2022 at 09:19:19 UTC, Carsten Schlote 
> wrote:
>> Hi,
>>
>> today I had to write some unittests for the googletest 
>> framework. For one of the tests I had to read binary files, 
>> and fed their contents to some code for testing. In D this is 
>> really simple:
>>
>> [...]
>>
>> So, if you need an example, why C++ simply s***s and D just 
>> rocks, use this... ;-)
>>
>>     Regards
>>       Carsten
>
> You're right on the fact that D std is better for that but 
> apparently there were shorter c++ alternatives (just searched 
> "stdc++ read file in vector"

If you can assume that the file isn't modified then use 
std::filesystem::file_size to obtain the size, allocate a buffer 
and use C-api to read the file in one go.



More information about the Digitalmars-d mailing list