小编nul*_*ter的帖子

为Object :: tr传递QString的更简单方法?

我希望我的应用程序是多语言的.这就是我Object::tr在我的应用中使用每个字符串的原因.很容易,当我有这个:

QObject::tr("message");

但有QString QObject::tr是很长的:

    QString msg = "";
    msg += "some kind of message";

    QMessageBox msgBox;
    msgBox.setText(QObject::tr(msg.toStdString().c_str()));
    msgBox.setIcon(QMessageBox::Warning);
    msgBox.exec();
Run Code Online (Sandbox Code Playgroud)

可以更容易吗?

c++ qt

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

从C++中的[0,1]中获取随机双数

我想生成随机双数x,其中0 <= x <= 1::

double x = ((double) rand() / (RAND_MAX));
Run Code Online (Sandbox Code Playgroud)

这是从[0,1]获取随机双数的正确方法吗?

c++ random

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

每字节负周期?rdtsc

我写了一些代码来测量每个字节的 CPU 周期。我变得消极,cpb但不知道为什么......它告诉我cpb = -0.855553 cycles/byte

我的伪代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

uint64_t rdtsc(){
    unsigned int lo,hi;
    __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
    return ((uint64_t)hi << 32) | lo;
}

int main()
{
    long double inputsSize = 1024;
    long double counter = 1;

    long double cpuCycleStart = rdtsc();

        while(counter < 3s)
            function(args);

    long double cpuCycleEnd = rdtsc();

        long double cpb = ((cpuCycleEnd - cpuCycleStart) / (counter *  inputsSize));

    printf("%Lf cycles/byte\n", cpb);

    return …
Run Code Online (Sandbox Code Playgroud)

c performance benchmarking cpu-usage

0
推荐指数
1
解决办法
678
查看次数

如何检查2个浮点数是否相等(有一些给定的误差值)?

我知道如何检查两个浮点数是否almost相等,简单代码:

bool compare(double a, double b)
{
    if(fabs(a - b) < (1.0 / 10000000))
        return true;
    else
        return false;
}
Run Code Online (Sandbox Code Playgroud)

但是当我有一些随机数据时,让我们说9.0和9.5,或者9.4我希望将它们视为相同数字,如何做到这一点?我的意思是,他们不相等,但我可以允许一些小错误+/- 0.5.有任何想法吗?

有了这个错误,我可以处理数字:

9.1 and 9.0 
3.1 and 3.6
-4.2 and -4.6
Run Code Online (Sandbox Code Playgroud)

平等的

c floating-point floating-point-precision

0
推荐指数
2
解决办法
1562
查看次数

如何将两张桌子从左到右彼此相邻漂浮并将它们居中?

我有两个表,我想彼此相邻,但希望它们位于页面的中心.

我几乎做到了,我只有一个问题,如何将它们对齐在页面的中心.我的例子:

演示

我的HTML:

<table class="table_on_the_left">
    <tr><td>
        hello demo here 
        </td></tr></table>

<table class="table_on_the_right">
    <tr><td>
        hello demo here 2 
    </td></tr></table>
Run Code Online (Sandbox Code Playgroud)

我的CSS:

table.table_on_the_left {
    position:center;
    float:left;
   }

  table.table_on_the_right {
    position:center;
    float:right;
  }
Run Code Online (Sandbox Code Playgroud)

html css

0
推荐指数
1
解决办法
9051
查看次数