【问题标题】:Issue C1083: cannot open include file: 'chrono': no such file or directory pops out问题 C1083:无法打开包含文件:'chrono':没有此类文件或目录弹出
【发布时间】:2015-10-25 17:32:57
【问题描述】:

我正在尝试制作一个让 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':没有这样的文件或目录”弹出。

如果您能提供帮助将不胜感激:)

【问题讨论】:

  • 您使用的是哪个编译器?可能是不完全支持C++11...
  • 我不使用这个编译器,但我认为你也必须设置QMAKE_CXXFLAGS += -std=c++11。这是讨论here
  • @CoryKramer 鉴于提问者使用 MSVC,您所指的标志不受支持且不必要。 MSVC 支持它所支持的任何东西,没有办法哄它支持更多。
  • 您使用的是哪个版本的 MSVC?
  • 我已经安装了 MSVC 2015 社区,但仍然遇到同样的问题。我应该删除 MSVC 2010 还是在 QT creator 中进行一些设置更改?

标签: c++ qt visual-c++ chrono


【解决方案1】:

您使用的 MSVC 版本太旧。错误源于编译器,而不是 Qt Creator。

【讨论】:

  • 我目前正在使用 MSVC 2010。我将安装最新版本的 MSVC 并重试。感谢您的评论:)
  • 我已经安装了 MSVC 2015 社区,但仍然遇到同样的问题。我应该删除 MSVC 2010 还是在 QT creator 中进行一些设置更改?
  • @apolokr2000 当然,您需要设置您的 Qt 版本和工具包以使用正确的编译器,并且您需要使用 MSVC 2015 (!!) 编译 Qt。
  • 您能告诉我如何设置 Qt 版本和套件以使用 MSVC2015 并使用 MSVC 2015 编译 Qt 吗?我一直在搜索谷歌,但找不到路,或者我无法理解它 T.T. 也许是因为我刚开始编程。如果您能告诉我如何设置 Qt 并使用 MSVC 2015 编译 Qt,那将是一个很大的帮助。在 google 中找不到任何地方。
  • @apolokr2000 1. 下载并解压 Qt 源代码。 2. 打开 MSVC 命令提示符。 3. 为 Qt 创建一个构建文件夹(not 在源文件夹中!)。 4. cd 进入构建文件夹。 5. &lt;src path&gt;\configure -opensource -debug-and-release -ltcg -nomake examples -angle -platform win32-msvc2015 6. nmake &amp;&amp; nmake install 7. 现在你已经构建了 Qt。下载Qt Creator并给-make-tool jom配置会更快;首先确保将jom.exe 的文件夹添加到您的路径中。 jom 与 Creator 一起提供。注意:Qt 的文档都有!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-14
  • 2014-08-02
  • 2010-10-27
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 2017-05-04
相关资源
最近更新 更多