printf, writeln, writefln

ag0aep6g anonymous at example.com
Wed Dec 7 06:08:33 UTC 2022


On 07.12.22 01:35, ryuukk_ wrote:
> On Tuesday, 6 December 2022 at 23:41:09 UTC, H. S. Teoh wrote:
[...]
>> In D, strings are not the same as char*.  You should use 
>> std.conv.fromStringZ to convert the C char* to a D string.
[...]
> no, you don't "need" to use std conv
> 
> 
> Here is an alternative that doesn't allocate
[...]
>      // now we got a len, we can build a D string, remember, it's just a 
> slice
> 
>      string str = cast(string) ret[0 .. len];

Slicing is exactly what std.string.fromStringz does.

<https://dlang.org/phobos/std_string.html#.fromStringz>:
"The returned array is a slice of the original buffer. The original data 
is not changed and not copied."


More information about the Digitalmars-d-learn mailing list