gpt4 book ai didi

c++ - 我正在尝试运行使用 Boost 库的 C++ 代码

转载 作者:行者123 更新时间:2023-11-28 07:21:35 28 4
gpt4 key购买 nike

我宁愿不下载任何东西,但如果必须,我可以这样做。我只是想在许多在线编译器上使用 Boost 库运行一个简单的多线程程序,但它们甚至都无法识别

#include <boost/thread.hpp>

using namespace boost::this_thread;

代码本身取自这个链接: https://www.quantnet.com/threads/c-multithreading-in-boost.10028/

我用谷歌搜索并尝试了很多在线编译器,但似乎没有一个愿意识别 Boost 或其相关库。

这是代码:

#include <iostream>
#include <boost/thread.hpp>

using namespace std;
using namespace boost;
using namespace boost::this_thread;

// Global function called by thread
void GlobalFunction()
{
for (int i=0; i<10; ++i) {
cout<< i << "Do something in parallel with main method." << endl;
boost::this_thread::yield(); // 'yield' discussed in section 18.6
}
}

int main()
{
boost::thread t(&GlobalFunction);
for (int i=0; i<10; i++) {
cout << i <<"Do something in main method."<<endl;
}
return 0;
}

最佳答案

Wandbox是一个包含 BOOST 库的在线 C++ IDE。它支持最新的 BOOST 版本(当前为 1.67.0)

注意:您的代码示例在 1.64.0 之前的 BOOST 版本中运行良好。

关于c++ - 我正在尝试运行使用 Boost 库的 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19372810/

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