Can';t使用dlang.org上的代码示例
我有一些无法编译的代码Can';t使用dlang.org上的代码示例,d,D,我有一些无法编译的代码 import std.string; import std.net.curl; int main(string[] argv) { string a = get("http://google.com"); return 0; } Error: cannot implicitly convert expression (get("http://google.com", AutoProtocol())) of type char[] to string
import std.string;
import std.net.curl;
int main(string[] argv)
{
string a = get("http://google.com");
return 0;
}
Error: cannot implicitly convert expression (get("http://google.com", AutoProtocol())) of type char[] to string
里面有密码
import std.net.curl, std.stdio;
// Return a string containing the content specified by an URL
string content = get("dlang.org");
为什么我不能编译相同的代码?示例错误-get返回char[]而不是string。区别在于字符串是不可变的,而字符不是 有两种解决方法:
char[] a = get("http://google.com"); // or you could do auto a = ... instead
或
第二个生成数据的不可变副本。第一个使用了适当的类型。示例是错误的-get返回char[]而不是string。区别在于字符串是不可变的,而字符不是 有两种解决方法:
char[] a = get("http://google.com"); // or you could do auto a = ... instead
或
第二个生成数据的不可变副本。第一个使用适当的类型。我建议使用通用的std.conv.to!挂断电话。我个人喜好。我推荐通用的std.conv.to!挂断电话。个人喜好我赞成。