小编pri*_*ion的帖子

在 C++ 中将时间从一种环境转换为另一种环境

我从服务器端(运行 .NET 应用程序)获取 uint64_t 值到我用标准 C++ 编写的应用程序(必须在 Windows 和 Linux 上运行)。

这个数字代表 Windows 文件时间 - 也就是自 1601-01-01 00:00:00 UTC 纪元以来的 100 纳秒间隔。

我需要在我的应用程序中返回时间的字符串表示,精度为纳秒(这是我从服务器获得的值的精度),所以我必须使用 chrono 库。

由于C++的时代是0001年1月1日到1970年1月1日,我首先需要计算从1970年到1601年的偏移量,然后从我从服务器得到的数字中减去它。为了做到这一点,我首先必须将我从服务器获得的值表示为 chrono::time_point,并以 100 纳秒的间隔计算纪元 1601-01-01 00:00:00 UTC,因此它和值我得到了相同的规模。

After i have the addjustedTimeFromServer - which is the value i get from the server minus (in the chrono::time_point form) the offset, i need to convert it into std::time_t in order to extract the value with accuracy of seconds, and then from the chrono::time_point i need to extract …

c++ time datetime date c++-chrono

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

使用unique_ptr来管理三维数组

我使用以下方式分配了三维:

board = new char**[depth];
    for (int d = 0; d < depth; d++)
    {
        board[d] = new char*[rows];
        for (int i = 0; i < rows; i++) {
            board[d][i] = new char[cols];
            for (int j = 0; j < cols; j++) {
                board[d][i][j] = 'k';
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在我想使用unique_ptr来管理它,但我不知道如何使用unique_ptr公开的接口启动这样的结构.

c++ arrays memory-management unique-ptr

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

标签 统计

c++ ×2

arrays ×1

c++-chrono ×1

date ×1

datetime ×1

memory-management ×1

time ×1

unique-ptr ×1