[Issue 6157] to!string should work for various pointer types
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 20 13:45:41 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=6157
--- Comment #7 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2014-02-20 13:45:37 PST ---
(In reply to comment #6)
> The example is not good, dup duplicated only 3 chars, so the resulting strings
> are not null-terminated.
IIRC these used to be compile-time errors. But yes, \0 is missing.
-----
import std.conv;
import std.stdio;
void main()
{
char* cstr = "foo\0".dup.ptr;
wchar* wstr = "foo\0"w.dup.ptr;
dchar* dstr = "foo\0"d.dup.ptr;
auto x = to!string(cstr);
auto y = to!string(wstr);
auto z = to!string(dstr);
writeln(x); // foo
writeln(y); // memory address
writeln(z); // memory address
}
-----
But nowadays I get the feeling a fromUTFz would be more appropriate.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list