Windows 10 上的以下代码:
#include <chrono>
#include <iostream>
int main(void)
{
const auto p1 = std::chrono::system_clock::now();
const auto p2 = std::chrono::steady_clock::now();
std::cout << "system_clock seconds since epoch: "
<< std::chrono::duration_cast<std::chrono::seconds>(
p1.time_since_epoch()).count()
<< '\n';
std::cout << "steady_clock seconds since epoch: "
<< std::chrono::duration_cast<std::chrono::seconds>(
p2.time_since_epoch()).count()
<< '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
system_clock seconds since epoch: 1690157550
steady_clock seconds since epoch: 434342
Run Code Online (Sandbox Code Playgroud)
因此,steady_clock
即使我要求自纪元以来的时间,似乎也会计算自上次启动以来的时间。对我来说这是不正确的。自纪元以来,它并没有给我时间。
我正在尝试将数据文件写入磁盘,以便可以缓存无法放入内存的大量数据。在一些早期测试中,我发现有时会写入数据,有时不会。这是一个示例,显示该过程不起作用:
using System.IO;
using System;
namespace TestBinaryWriter
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
double dFoo = 1234.1234;
BinaryWriter bw = new BinaryWriter(File.OpenWrite("asdf"));
bw.Write(dFoo);
bw.Write(BitConverter.GetBytes(dFoo));
}
}
}
Run Code Online (Sandbox Code Playgroud)
文件“asdf”的内容是空的,我不明白为什么。
这是我通过复制各种教程和 SO 帖子创建的代码:
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import QObject, pyqtSignal, QThread
class Worker(QThread):
def __init__(self):
QThread.__init__(self)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
worker = Worker()
worker.start()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.resize(640, 480)
window.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
这很简单,但是当我运行它时,python 立即崩溃。我正在使用 Anaconda3,我非常确定 python 环境设置正确,但我可能是错的。我在 Windows 10、64 位、Anaconda3 和 Python 3.5(64 位)上。我使用 conda 安装了 qt4。
我有一个帧率列表和一个相关的屏幕分辨率列表.问题是我的resoltuions列表中有大量重复项.实际上,我也在帧率列表中获得了大量的重复项(非常感谢,Windows!),但是当我对原始列表进行排序时,通过简单的比较消除了这些重复项.我想我想用它std::algorithm
来帮助我消除我的重复,但我无法让它工作.
码:
#include <algorithm>
#include <vector>
#include <iostream>
struct resolution {
int w;
int h;
};
int main(void) {
std::vector<std::pair<int, std::vector<resolution>>> vec;
for (int i = 0; i < 5; i++) {
std::pair<int, std::vector<resolution>> p;
p.first = i;
for (int j = 0; j < 5; j++) {
resolution res;
res.w = j;
res.h = j;
p.second.push_back(res);
}
vec.push_back(p);
}
for (std::vector<std::pair<int, std::vector<resolution>>>::iterator it = vec.begin();
it != vec.end();
++it) {
it->second.erase(std::unique(it->second.begin(), it->second.end()), it->second.end());
}
for (std::vector<std::pair<int, std::vector<resolution>>>::iterator …
Run Code Online (Sandbox Code Playgroud)