#include <thread>
#include <iostream>
#include <functional>
using namespace std;
void show(const char *str, const int id)
{
cout << "线程 " << id + 1 << " :" << str << endl;
}
int main()
{
thread t1(show, "hello cplusplus!", 0);
thread t2(show, "你好,C++!", 1);
thread t3(show, "hello!", 2);
return 0;
}
应该是正确的绑定方法,为什么一直报错呢?
编译错误还是运行错误?
使用IDE是什么? 是不是 IDE 不支持C++ 11 语法?
vs2019 中执行 没有问题.
主线程需要等待子线程结束吧?