小编Igo*_*tov的帖子

std.algorithm.joiner(string [],string) - 为什么结果元素是dchar而不是char?

我尝试编译以下代码:

import std.algorithm;
void main()
{
    string[] x = ["ab", "cd", "ef"]; // 'string' is same as 'immutable(char)[]'
    string space = " ";
    char z = joiner( x, space ).front(); // error
}
Run Code Online (Sandbox Code Playgroud)

dmd带有错误的结尾编译:

 test.d(8): Error: cannot implicitly convert expression (joiner(x,space).front()) of type dchar to char
Run Code Online (Sandbox Code Playgroud)

更改char zdchar z确定错误消息,但我很感兴趣,为什么它出现在第一位.

为什么结果joiner(string[],string).front()是dchar而不是char?

(文档http://dlang.org/phobos/std_algorithm.html#joiner中没有任何内容)

d phobos dmd

7
推荐指数
1
解决办法
389
查看次数

为什么readf没有按预期运行?

import std.stdio;

void main(){

  int n;
  while(readf("%d", &n)){
    if(n == 11)
      break;
    writeln(n);
  }
}
Run Code Online (Sandbox Code Playgroud)

第一次迭代工作,并打印n,但之后readf()永远不会返回.

该文档只有一行解释readf():

uint readf(A ...)(以char []格式,A args);

   For­mat­ted read one line from stdin.
Run Code Online (Sandbox Code Playgroud)

我做错了吗?或者有什么问题readf()吗?我只需要从标准输入中读取数字.

使用:DMD 2.054 64位

d dmd

6
推荐指数
1
解决办法
777
查看次数

什么时候应该使用BitVector32?

我正在做一个项目,在某个时刻我需要显示一个月的时间,这些天仍然可用。有一个功能可以计算哪些日期可用。我的同事说:“哦,我们知道,您应该返回a BitVector32。这是使用布尔值列表时最有效的方法。” 我会用一个List<bool>或类似的东西。BitVector32在您实际使用位时,对我而言,A 似乎是低级内容。

所以,问题是。您是否应该BitVector32在需要少于32个布尔值的布尔值列表时使用Every,还是仅将其用于低级内容?

.net boolean bitvector base-class-library

5
推荐指数
1
解决办法
2801
查看次数

为什么readf没有返回值?

根据文档,readf应该返回一个uint.但即便是这个简单的例子也无法编译:

你好ð

import std.stdio;

void main() {
    int x;
    uint r = readf("%s", &x);    
}
Run Code Online (Sandbox Code Playgroud)

错误信息:

hello.d(5): Error: expression readf("%s",& x) is void and has no value
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么吗?

我正在使用dmd(Digital Mars D)编译器v2.050.

d dmd

5
推荐指数
1
解决办法
148
查看次数

据称,在.NET 4.5中实现IDisposable的X509Store在哪里?

这篇MSDN文章指出X509Store该类IDisposable在.NET 4.5中实现.早期版本的.NET不是这种情况.

即使我安装了Windows 8.1,Visual Studio 2013,所有.Net版本,从2.0到4.5.1,我只能看到X509Store最新的System.dll(v4.0.30319,又名.NET 4.5)中的.NET 4版本.VS对象浏览器还显示X509StoreSystem.dll v4.0.30319中没有实现IDisposable像MSDN文章所说的那样.

我错过了什么以及如何X509Store从.NET 4.5 获得?MSDN错了吗?这不是第一次,但仍然是.是否有一个模糊的Windows Update KB修复程序?

security msdn x509certificate2 x509certificate .net-4.5

5
推荐指数
1
解决办法
943
查看次数

D有像Java的扫描仪吗?

像Java的扫描仪那样在D中是否有流解析器?在哪里你可以nextInt()去取一个intnextLong()一个long等等.

d java.util.scanner

4
推荐指数
1
解决办法
106
查看次数

D编程语言的文件I/O.

我正在尝试遵循一个简单的教程,无法使用以下代码:

void main(string args[])
{
  auto f = File("test.txt", "w");
  f.writeln("Hello, Worlds!");
}
Run Code Online (Sandbox Code Playgroud)

我在Windows上使用dmd编译器.

d dmd

3
推荐指数
1
解决办法
1587
查看次数

无法覆盖结构的opCmp和opEquals

来自D的文档:

或者,您可以使用auto ref参数声明单个模板化opEquals函数:

bool opEquals()(auto ref S s) { ... }
Run Code Online (Sandbox Code Playgroud)

<...>

如果struct声明了一个opCmp成员函数,它应该遵循以下形式:

int opCmp(ref const S s) const { ... }
Run Code Online (Sandbox Code Playgroud)

为什么以下代码无法编译呢?

import std.stdio;
import std.conv;

struct Fgs {
    int v;
    this(int iv) {
        v = iv;
    }

    bool opEquals()(auto ref Fgs another) {
        return v == another.v;
    }

    int opCmp(ref const Fgs another) const {
        if (this == another) {
            return 0;
        } else if (this.v < another.v) {
            return -1;
        } else {
            return 1; …
Run Code Online (Sandbox Code Playgroud)

d dmd

3
推荐指数
1
解决办法
298
查看次数