gpt4 book ai didi

c++ - 代码块 C++ 线程错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:32:12 27 4
gpt4 key购买 nike

<分区>

我有一个问题,包括线程库。以下代码:

#include <string>
#include <iostream>
#include <thread>

using namespace std;

//The function we want to make the thread run.
void task1(string msg)
{
cout << "task1 says: " << msg;
}

int main()
{
// Constructs the new thread and runs it. Does not block execution.
thread t1(task1, "Hello");

//Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
t1.join();
}

产生这些错误:

enter image description here

代码取自另一个stackoverflow问题的答案。我对代码块和 C++ 还很陌生,所以请向我解释我做错了什么。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com