Gar*_*hby 7 string pointers casting d char
我有一个标准的char指针,我试图强制转换为字符串.
// string to char*
char *x = cast(char*)("Hello World\0");
// char* to string?
string x = cast(string)x;
string x = cast(immutable(char)[])x;
Run Code Online (Sandbox Code Playgroud)
错误!
有关如何将char*转换为D中的字符串的任何想法?
eco*_*eco 15
使用std.conv.to从转换char*到string.使用std.string.toStringZ走另一条路.
import std.string;
import std.stdio;
import std.conv;
void main()
{
immutable(char)* x = "Hello World".toStringz();
auto s = to!string(x);
writeln(s);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2872 次 |
| 最近记录: |