小编Fre*_*Kay的帖子

可以全局设置qDebug()浮点精度和数字格式吗?

我想使用qDebug(),qInfo()等自定义默认浮点精度和数字格式.

有没有办法在全球范围内定义?

想象一下:

double num = 1.2;
qDebug() << "My floating point Number is: " << QString::number(num, 'f', 2);
//Output: My floating point Number is 1.20
Run Code Online (Sandbox Code Playgroud)

现在我想在每次写一个数字时避免使用QString :: number(num,'f',2),而是更喜欢使用标准的percision和format.

c++ qt number-formatting

7
推荐指数
2
解决办法
6067
查看次数

反向复制数组

我想以相反的顺序将数组复制到同一个数组的末尾,同时更改值的代数符号.

它是这样的:

void foo()
{
    std::vector<int> vec;
    for(int = 0; i < 5; i++)
    {
        vec.push_back(i);
    }

    //Now i want the values in vec to be copied to the end in reverse order.
    //I would like to have something like that :
    std::copy(std::end(vec), std::begin(vec), std::back_inserter(vec))

    //so now vec should look like: 0 1 2 3 4 4 3 2 1 0
    //But I want: 0 1 2 3 4 -4 -3 -2 -1 -0

}
Run Code Online (Sandbox Code Playgroud)

是否已经存在std标准函数,我可以调整以执行我想要的操作(如partition_copy或其他)或者我是否可能必须使用我自己的东西,如std :: for_each和适当的lambda函数?

c++ arrays reverse

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

标签 统计

c++ ×2

arrays ×1

number-formatting ×1

qt ×1

reverse ×1