c++ - 为什么它说#include包含在c++中时不包含?
问题描述
我是多线程的新手,但我在这个网站上找到了一个关于简单多线程代码的答案。我完全复制了它,#include <thread>
但后来它在终端(我正在运行 Visual Studio Code)中说我没有包含线程。这是代码。
#include <string>
#include <iostream>
#include <thread>
using namespace std;
void task1(string msg)
{
cout << "task1 says: " << msg;
}
int main()
{
thread t1(task1, "Hello");
t1.join();
}
这是我看到的错误:
c:\Users\Lol\Desktop\C++\Thread testing\Threadtest.cpp: In function 'int main()':
c:\Users\Lol\Desktop\C++\Thread testing\Threadtest.cpp:18:5: error: 'thread' was not declared in this scope
18 | thread t1(task1, "Hello");
| ^~~~~~
c:\Users\Lol\Desktop\C++\Thread testing\Threadtest.cpp:5:1: note: 'std::thread' is defined in header '<thread>'; did you forget to '#include <thread>'?
4 | #include <thread>
+++ |+#include <thread>
5 |
c:\Users\Lol\Desktop\C++\Thread testing\Threadtest.cpp:24:5: error: 't1' was not declared in this scope; did you mean 'tm'?
24 | t1.join();
| ^~
| tm
The terminal process terminated with exit code: 1
解决方案
推荐阅读
- r - eval(family$initialize) 中的错误:y 值必须为 0 <= y <= 1
- javascript - 如何将“this”对象放入回调函数?
- r - 计算列表中元素的平均值
- scala - Scala:将配置数据作为全局对象
- scheme - 不是给出批处理模式的命令,而是给出 .scm 文件路径?
- python - 从文本文件中的输入中按字母查找多个单词
- go - 如何将 row.Scan() int32 放入 Golang gRPC protobuf Enum 字段?
- linux-kernel - 如何通过从用户空间提供文件指针来从内核空间接收文件指针
- scala - 更新 Spark 数据框以从另一个数据框填充数据
- r - R:调用包中的导入函数时出错