當我嘗試構建 Google 測驗 c 專案時,我發現了錯誤
Error C3861 't1': identifier not found
Error C2065 't1': undeclared identifier
Error C2039 'thread': is not a member of 'std'
Error C2065 'thread': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 't1'
我的測驗代碼是:
#include <future>
#include <thread>
#include "pch.h"
TEST(...)
{
// preconditions here
std::thread t1([&] {
Sleep(100);
testee.enqueue(item);
});
t1.join();
// other logic
}
為什么我不能在我的專案中使用 std::thread 和其他 C 11 特性?我該怎么做?
uj5u.com熱心網友回復:
#include "pch.h"必須是第一。之前的其他 #include 指令#include "pch.h"將被忽略。
uj5u.com熱心網友回復:
為什么我不能在我的專案中使用 std::thread 和其他 C 11 特性?
潛在原因 1:除非使用 C 11 或更高版本的標準,否則不能使用 C 11 功能。
潛在原因 2:std::thread除非包含定義std::thread. 它在 header 中定義<thread>。
uj5u.com熱心網友回復:
關于pch.h,可以參考這個
關于C 11的使用,可以在專案屬性>配置屬性>通用>C 語言標準中設定。我建議你使用 C 14,因為 C 14 已經包含了 C 11 的特性。

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/397888.html
