我目前正在運行一個測驗程式,該程式可以很好地在線執行 (replit.com),但是當我在本地運行它時(在帶有 gcc 和 g 的 Windows 10 上)我收到一個錯誤:
test.cpp: In function 'int main()':
test.cpp:18:8: error: 'std::this_thread' has not been declared
std::this_thread::sleep_for(std::chrono::milliseconds(time));
這是我的程式:
#include <iostream>
#include <thread>
#include <chrono>
#include <random>
#include <string>
int randomInt (int MIN, int MAX) {
std::random_device rd;
std::default_random_engine eng(rd());
std::uniform_int_distribution<int> distr(MIN, MAX);
return distr(eng);
}
int main() {
int loop = 20;
for (int i = 0; i < loop; i ) {
int time = randomInt(10, 100);
std::this_thread::sleep_for(std::chrono::milliseconds(time));
}
return 0;
}
為什么會發生這種情況?
uj5u.com熱心網友回復:
我回到replit.com 看看他們在做什么來編譯程式。顯然他們使用了-pthreads開關:
g -pthread -std=c 17 -o main main.cpp
現在對我有用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/357878.html
上一篇:LaravelTaskSchedulerServer無法在WindowsServerXampp上運行
下一篇:單擊時漢堡選單覆寫不會顯示X
