【问题标题】:thread.h no such file or directory visual studio projectthread.h 没有这样的文件或目录 Visual Studio 项目
【发布时间】:2016-09-09 08:02:05
【问题描述】:

我是新手,只是想了解它是如何工作的。我正在使用 Visual Studio,打开了一个在 c++ Release 模式下运行的现有项目,win32。我需要创建一个线程才能运行一系列指令。 一开始我创建了一个简单的 cpp 文件,如下例所示,我没有遇到任何问题:http://www.cplusplus.com/reference/thread/thread/。我只编译了cpp文件

但是当我在更大的项目中添加 #include 行时,它被标记为错误并编译/构建项目给了我:Error C0183: Cannot open include file: no such file or directory

我该如何解决这个问题?预先感谢您的回复。

编辑:我在代码的开头添加了这个,主要看起来像这样:

#include <stdio.h>
#include <thread.h>

int _cdecl wmain(_In_ int argc, wchar_t *argv[]) { // bla bla }

Please note that it was running without errors until I added  
 #include <thread.h>, or #include <thread>

【问题讨论】:

  • 考虑添加有关该问题的更多详细信息,例如您的代码片段,显示的错误日志等。
  • 你能告诉我们你的thread.h和主代码是什么样子的吗,只是你做了包含的部分吗?您是否包含 '' 而不是 ?其他重要的事情是将文件添加到正确的文件夹中。请给我们一些额外的信息。
  • 你不需要写thread.h,但你应该使用#include &lt;thread&gt;
  • 感谢您的回复。请参阅上面我编辑的消息。在某处我读到“标准线程支持是一项新功能(在 C++11 标准中定义)”但我不明白我应该如何修复它
  • #include &lt;cstdio&gt;#include &lt;thread&gt; 可能是个好主意,但是...但是,您正在运行 VS2010,不是包括 C++11 线程库。然而,它确实实现了许多 03 项,但没有实现线程

标签: c++ multithreading visual-studio-2010 include


【解决方案1】:

VS2010 早于标准化的&lt;thread&gt;,但它确实有来自&lt;process.h&gt;_beginthread。但是,它的灵活性要差得多:它只能启动具有签名void (void* arg) 的函数。

最简单的方法是让你的线程入口函数成为一个类的静态方法,并将this 指针作为void* arg 传递。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 2022-01-16
    • 2014-02-25
    • 1970-01-01
    相关资源
    最近更新 更多