我是 C 新手,撰寫了我的第一個 main.cpp,但出現錯誤,不完全是錯誤,這是一個邏輯錯誤,我猜是因為我撰寫了以下代碼:
#include <iostream> // including the iostream
using namespace std; // using the std namespace
int main() { // starting the main function
cout << "Hello World!" << endl; // My favorite line of code in all the of languages
return 0; // returning 0 to stop the function execution
}
在我期望的終端
C:\Users\DELL\Desktop> g main.cpp
Hello World!
C:\Users\DELL\Desktop>
但它只是顯示:
C:\Users\DELL\Desktop> g main.cpp
C:\Users\DELL\Desktop>
沒有輸出,但是當我嘗試使用 Code::Blocks 時,它作業得很好!在 vscode 終端中,同樣的問題,但是當我運行檔案時,它又可以作業了!為什么它不起作用?我在命令提示符中進行了嘗試,安裝了 Windows 終端,并在其中進行了嘗試(將終端保留為命令提示符,因為我不知道 PowerShell 是什么以及如何使用它)但是任何方法都不起作用。
請告訴我該怎么做,我是 C 新手,只知道一些事情。
uj5u.com熱心網友回復:
很簡單,在 g "file.cpp" 之后,你會在你當前的作業目錄中得到一個輸出檔案,也就是可執行檔案。C 是編譯的,而不是解釋的。
該輸出檔案是可執行檔案,默認情況下將是“a.out”,使用 gcc/g 。您可以使用選項“-o”來指定輸出目錄。
uj5u.com熱心網友回復:
g main.cpp將編譯檔案并生成a.exe,您只需a.exe在終端中輸入即可列印Hello World!。
uj5u.com熱心網友回復:
該命令g main.cpp創建檔案 a.out 或 a.exe。創建該檔案后,您需要./a.out在 Linux 和 Mac 或a.exeWindows 上通過命令運行它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/444270.html
上一篇:回傳值時布爾檢查行為例外
