pointers - How to cast a char* to string in D? -
pointers - How to cast a char* to string in D? -
i have standard char pointer im trying cast string.
// string char* char *x = cast(char*)("hello world\0"); // char* string? string x = cast(string)x; string x = cast(immutable(char)[])x;
error!
any ideas how cast char* string in d?
use std.conv.to
convert char*
string
. utilize std.string.tostringz
go other way.
import std.string; import std.stdio; import std.conv; void main() { immutable(char)* x = "hello world".tostringz(); auto s = to!string(x); writeln(s); }
string pointers casting char d
Comments
Post a Comment