我正在尝试编写一个程序,使 6 个数字随机出现。
这是我的 .pro 文件
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Lotto
TEMPLATE = app
CONFIG += c++11
SOURCES += main.cpp\
mainwindow.cpp \
lottogenerator.cpp
HEADERS += mainwindow.h \
lottogenerator.h
FORMS += mainwindow.ui
这是我的 .h 文件
#ifndef LOTTOGENERATOR_H
#define LOTTOGENERATOR_H
#include <string>
#include <random>
#include <array>
#include <chrono>
class LottoGenerator
{
public:
typedef std::chrono::high_resolution_clock myclock;
LottoGenerator();
std::array<int, 6> get();
private:
int rand();
std::mt19937 *engine;
std::uniform_int_distribution<int> distribution;
myclock::time_point beginning = myclock::now();
};
#endif // LOTTOGENERATOR_H
这是我的 .cpp 文件。
#include "lottogenerator.h"
LottoGenerator::LottoGenerator()
: distribution(1,45)
{
myclock::duration d = myclock::now() - beginning;
unsigned int seed = d.count();
engine.seed(seed);
}
std::array<int, 6> LottoGenerator::get()
{
std::array<int, 6> numbers;
numbers[0] = rand();
numbers[1] = rand();
numbers[2] = rand();
numbers[3] = rand();
numbers[4] = rand();
numbers[5] = rand();
return numbers;
}
int LottoGenerator::rand()
{
return distribution(engine);
}
当我运行时,弹出“C1083:无法打开包含文件:'chrono':没有这样的文件或目录”。
如果您能帮忙,我将不胜感激:)
您使用的 MSVC 版本太旧。该错误源自编译器,而不是 Qt Creator。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)