#include <iostream>
#include <string>
using namespace std;

int main() {
    // 変数と型
    string name = "たろう";
    int age = 16;
    double height = 170.5;
    bool isStudent = true;

    // 出力
    cout << "名前: " << name << endl;
    cout << "年齢: " << age << endl;

    // 入力
    string input;
    cin >> input;

    // 条件分岐
    if (age >= 18) {
        cout << "成人です" << endl;
    } else {
        cout << "未成年です" << endl;
    }

    // ループ
    for (int i = 0; i < 5; i++) {
        cout << i << endl;
    }
    return 0;
}
⚠️ C++ならではの注意点
  • #include でヘッダファイルを読み込む必要がある
  • 文の末尾には必ず ;(セミコロン)をつける
  • main() 関数は int を返す(最後に return 0;
  • Pythonと違いインデントではなく { } でブロックを定義する