第一堂 C++ 課

Hello World!

我們直接來看一下,要如何在螢幕上輸出 Hello World 吧!

學完後,就可以說:我會C++喔

#include<iostream>
using namespace std;

int main(){
    cout<<"Hello World!\n";
}

程式應該會輸出:

Hello World!

下面,我們就一個一個來看,每一行在做什麼吧!

標頭檔

#include 這句,意思是引入名為 iostream 的標頭檔。

標頭檔wiki

簡單來說,是存放你要使用的功能的地方。

例如,假如你想要使用 cout 這個功能,便需要在程式的開頭加上這行,因為 cout 是 iostream 裡的功能,所以必須 include 後才能使用。

#include<iostream>

命名空間

using namespace std 這句,意思是使用名為 std 的命名空間。

教學