我正在使用Visual Studio 2013.项目经常拒绝编译.如果我撤消任何更改,它仍然无法编译.我发现重新创建整个项目是有效的.我想实际解决这个问题.我得到的错误是:
1>Critic.cpp : fatal error C1041: cannot open program database 'c:\users\username\desktop\projectName\projectName\x64\debug\vc120.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
Run Code Online (Sandbox Code Playgroud)
我试过按照这些说明无济于事:http://msdn.microsoft.com/en-us/library/dn502518.aspx
有没有其他人遇到这个并找到了修复?
我的程序需要在某个范围内生成许多随机整数(int min,int max).每次通话都有不同的范围.什么是好的(最好是线程安全的)方法呢?以下不是线程安全的(并使用rand(),人们似乎不鼓励):
int intRand(const int & min, const int & max)
{
return (rand() % (max+1-min)) + min;
}
Run Code Online (Sandbox Code Playgroud)
这要慢得多,但使用<random>:
int intRand(const int & min, const int & max) {
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(min,max);
return distribution(generator);
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西就是我想要的(虽然changeParameters函数不存在):
int intRand(const int & min, const int & max) {
static std::default_random_engine generator;
static std::uniform_int_distribution<int> distribution(0, 10);
distribution.changeParameters(min, max);
return distribution(generator);
}
Run Code Online (Sandbox Code Playgroud)
另一个选择是uniform_int_distribution在第一个例子中使用mod然后使用mod.但是,我正在进行统计工作,所以我希望数字来自尽可能无偏差的分布(例如,如果使用的分布范围不是(max-min)的倍数,则分布将略微偏置).这是一个选择,但同样,我想避免它.
解决方案此解决方案来自@ konrad-rudolph @ mark-ransom和@mathk的答案.随机数发生器的播种是为了满足我的特殊需要.更常见的方法是使用时间(NULL).如果你在同一秒内制作了很多线程,那么他们就会获得相同的种子.即使使用clock()也是一个问题,所以我们包含了线程ID.缺点 - 这会泄漏内存 - 每个线程一个生成器.
#if …Run Code Online (Sandbox Code Playgroud) 请注意,std :: normal_distribution :: operator()不是 const,也不是const方式.(其他一些发行版具有以const方式运行的()运算符,但也未定义为const).
鉴于std :: normal_distribution :: operator()不是const,在多个线程中使用相同的normal_distribution对象是否仍然安全?随机标题中的所有发行版都安全吗?
编辑:也就是说,以下成员函数抛出一个错误,因为函数是const但是使用operator(),它可以改变d.通过声明d是可变的来解决这个问题总是安全的吗?
class MyClass
{
public:
MyClass::MyClass(double mu, double sigma)
{
d = normal_distribution<double>(mu, sigma);
}
double MyClass::foo(std::mt19937_64 & generator) const
{
return d(generator);
}
private:
std::normal_distribution<double> d;
}
Run Code Online (Sandbox Code Playgroud) 在C#中,我有一个RichTextBox,我想得到光标的当前行.我发现的每个答案都说使用:
int currentLine = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart);
Run Code Online (Sandbox Code Playgroud)
但是,richTextBox1.SelectionStart仅在您对文本进行更改时更新.如果您使用箭头键移动光标,它不会更新(我已经通过在我移动时打印SelectionStart来验证这一点).
即使使用箭头键移动光标,如何以跟踪它的方式获取光标的当前行?
我在Win8中使用VS2012.
编辑: terrybozzio的答案显示了问题.对于有此问题的其他人,您不能将代码放在richTextBox1_TextChanged中.您需要将它放在richTextBox1_SelectionChanged中.
tl; dr:当我以一种方式编译代码时,可执行文件会快速运行.当我使用我的makefile时,它慢了~10倍(可执行速度,而不是编译时间).
当我编译以下代码(使用Eigen包)时:
#include <Eigen/Dense> // For matrix math
#include <iostream>
using namespace std;
using namespace Eigen;
// Loop an infinite number of times, computing dot products.
int main(int argc, char * argv[]) {
setNbThreads(16);
initParallel(); // Tell Eigen that we're going to be multithreaded.
int n = 100;
VectorXf a(n), b(n);
for (int counter = 0; true; counter++) {
a[0] = a.dot(b) / n;
if ((counter + 1) % 10000000 == 0) {
cout << counter / 10000000 << …Run Code Online (Sandbox Code Playgroud)