我正在嘗試在 Ubuntu 20.4 LTS 上的 Sublime-Text 上運行以下代碼片段。
#include <iostream>
int main(){
auto result = (10 <=> 5) > 0;
std::cout << result << std::endl;
return 0;
}
但這導致
ModernC .cpp: In function ‘int main()’:
ModernC .cpp:3:22: error: expected primary-expression before ‘>’ token
3 | auto result = (10 <=> 5) > 0;
| ^
[Finished in 271ms with exit code 1]
[cmd: ['g -std=c 2a ModernC .cpp -o ModernC && timeout 7s ./ModernC <input.txt>output.txt']]
[dir: /home/parth/.config/sublime-text/Packages/User]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
我還嘗試使用以下命令直接從終端運行它
g ModernC .cpp -std=c 2a -o ModernC
但這導致
ModernC .cpp: In function ‘int main()’:
ModernC .cpp:3:22: error: expected primary-expression before ‘>’ token
3 | auto result = (10 <=> 5) > 0;
我在我的 Windows 10 作業系統上嘗試了相同的代碼,它在那里運行良好。我做了一些研究。我發現從 GCC 8 開始就可以使用 C 20 功能。我也檢查了我的 G 版本。
g (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
所以我不認為版本是問題。如果有人也可以告訴我其中的錯誤,這里也是 sublime 的構建系統檔案。
{
"cmd" : ["g -std=c 2a $file_name -o $file_base_name && timeout 7s ./$file_base_name<input.txt>output.txt"],
"selector" : "source.cpp",
"shell":true,
"working_dir" : "$file_path"
}
所以這是我的疑問 -
- 如何修復未在 Sublime-Text 中運行的代碼?
- 如何修復未在終端中運行的代碼?
我搜索了修復程式,但發現的唯一問題是版本太低,顯然我的系統并非如此。此外,C 17 標準代碼運行良好。
編輯 1:將 g 更改為 g -10,仍然是同樣的錯誤。
編輯 2:已修復,<=> 由于某種原因被錯誤地更改為 <= >。
uj5u.com熱心網友回復:
您至少需要 GCC 版本 10。檢查編譯器支持 https://en.cppreference.com/w/cpp/compiler_support
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/427341.html
上一篇:重寫規則不適用
