認識C++ hello world程式的各種符號意義。
事前要求
參考「C++ hello world on Mac 2022」的hello.cpp。
hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "hello world\n";
return 0;
}
說明
#include <iostream>作用為把標準函式庫iostream標頭檔(header file)的內容加進目前的程式,如此便能使用iostream中定義的函式及變數。
using namespace std代表使用C++標準函式庫的std命名空間,所以使用iostream的cout時不用寫成std::cout,可直接寫cout。
int main() {...}函式為C++程式執行的進入點。
cout << "hello world\n";為把字串"hello world\n"以stream insertion operator(串流插入運算子)<<輸出給標準字元輸出串流cout並在終端機印出。\n為換行特殊符號。
return 0代表程式正常結束。
沒有留言:
張貼留言