Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
时钟每秒相当于C# 我在C++中有这个代码片段,很难把它转换成C<< /p> clock\u t now=clock(); myStartTime=开始; myTimeLimit=5//以秒为单位 对于(int-depth=2;((double)(现在-myStartTime))/(double)时钟每秒_C#_C++ - Fatal编程技术网

时钟每秒相当于C# 我在C++中有这个代码片段,很难把它转换成C<< /p> clock\u t now=clock(); myStartTime=开始; myTimeLimit=5//以秒为单位 对于(int-depth=2;((double)(现在-myStartTime))/(double)时钟每秒

时钟每秒相当于C# 我在C++中有这个代码片段,很难把它转换成C<< /p> clock\u t now=clock(); myStartTime=开始; myTimeLimit=5//以秒为单位 对于(int-depth=2;((double)(现在-myStartTime))/(double)时钟每秒,c#,c++,C#,C++,我应该这样做吗 var now = DateTime.Now; myStartTime = start; myTimeLimit = 5; for (int depth = 2; (now - myStartTime).TotalSeconds < myTimeLimit; depth += 2) { } var now=DateTime.now; myStartTime=开始; myTimeLimit=5; for(int depth=2;(现在-myStartTime).Tota

我应该这样做吗

var now = DateTime.Now;
myStartTime = start;
myTimeLimit = 5;

for (int depth = 2; (now - myStartTime).TotalSeconds < myTimeLimit; depth += 2)
{

}
var now=DateTime.now;
myStartTime=开始;
myTimeLimit=5;
for(int depth=2;(现在-myStartTime).TotalSeconds
您可以利用它作为更好的替代方案来实现这一点。比如说

var clt = new CancellationTokenSource(5000);
Task.Run(() => DoSomething(clt.Token));

private static void DoSomething(CancellationToken cltToken)
{
    for (int depth = 2; !cltToken.IsCancellationRequested; depth += 2)
    {
        // . . .
    }

    if (cltToken.IsCancellationRequested) {
        // Time limit reached before finding best move at this depth
    }
}
您可以利用它作为更好的替代方案来实现这一点。比如说

var clt = new CancellationTokenSource(5000);
Task.Run(() => DoSomething(clt.Token));

private static void DoSomething(CancellationToken cltToken)
{
    for (int depth = 2; !cltToken.IsCancellationRequested; depth += 2)
    {
        // . . .
    }

    if (cltToken.IsCancellationRequested) {
        // Time limit reached before finding best move at this depth
    }
}

是的,你就是这样做的,你找到的C++代码片段应该扔掉。对那样的计时器使用
时钟
,确实不是任何人都会推荐的。C和C++中有很多更好的选择,尤其是在C++中,有可移植的替代品(<代码>时钟<代码>函数,而在C和C++标准中,在不同的平台上不一样)。这个循环永远不会结束。@HenkHolterman循环将在条件满足时在内部中断,并且整个代码都在递归方法中。“在递归方法中”-哎哟。把它扔掉。是的,你就是这样做的。你应该找到的C++代码片段应该被扔掉。对那样的计时器使用
时钟
,确实不是任何人都会推荐的。C和C++中有很多更好的选择,尤其是在C++中,有可移植的替代品(<代码>时钟<代码>函数,而在C和C++标准中,在不同的平台上不一样)。这个循环永远不会结束。@HenkHolterman循环将在条件满足时在内部中断,并且整个代码都在递归方法中。“在递归方法中”-哎哟。把这个扔掉。