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.

class="lang-cpp prettyprint-override">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

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -