首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >this_thread / chrono尚未声明

this_thread / chrono尚未声明
EN

Stack Overflow用户
提问于 2021-09-17 17:56:54
回答 1查看 1.4K关注 0票数 1

我查看了许多StackOverflow帖子,但没有答案解决我的问题。

我有两个错误:

g++ .\main.cpp -fopenmp -o test

代码语言:javascript
运行
复制
.\main.cpp:12:14: error: 'std::this_thread' has not been declared
  12 |         std::this_thread::sleep_for(chrono::seconds(20000) );

.\main.cpp:12:37: error: 'chrono' has not been declared
  12 |         std::this_thread::sleep_for(chrono::seconds(20000) );

我现在的G++版本是:

g++.exe (MinGW.org GCC Buil-2) 9.2.0

守则是:

代码语言:javascript
运行
复制
#include <iostream>
#include <chrono>
#include <thread>
#include <omp.h>

int main()
{
    omp_set_num_threads(4);
    #pragma omp parallel
    {
        std::this_thread::sleep_for(chrono::seconds(20000) );
        std::cout << "Number of available threads: " << omp_get_num_threads() << std::endl;
        std::cout << "Current thread number: " << omp_get_thread_num() << std::endl;
        std::cout << "Hello, World!" << std::endl;
    }
    return 0;
}

我已经试过了11 & 14和17的-std=c++11

EN

回答 1

Stack Overflow用户

发布于 2021-09-17 20:45:07

我不确定它是对的,但是关于你的第二个错误,你能用

代码语言:javascript
运行
复制
std::this_thread::sleep_for(chrono::seconds(20000) );

代码语言:javascript
运行
复制
std::this_thread::sleep_for(std::chrono::seconds(20000));

我认为第一个错误取决于第二个错误,但我不确定。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69227735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档