// ===== CodeLab: C++ 入门:从 C 到 C++ =====
// 来源: https://aoerliang.dpdns.org/articles/cpp-intro
// 以下代码片段按文章出现顺序拼接, 共 4 段

// ----- 片段 1 (cpp) -----
#include <iostream>

int main() {
    std::cout << "Hello, C++!" << std::endl;
    return 0;
}

// ----- 片段 2 (cpp) -----
#include <iostream>
#include <string>
using namespace std;

int main() {
    string name;
    int age;
    cout << "姓名: ";
    cin >> name;
    cout << "年龄: ";
    cin >> age;
    cout << name << " 明年 " << age + 1 << " 岁" << endl;
    return 0;
}

// ----- 片段 3 (cpp) -----
int x = 42;
int& ref = x;   // ref 是 x 的别名
ref = 100;      // 等价于 x = 100
cout << x;      // 输出 100

// ----- 片段 4 (cpp) -----
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
// add(1, 2) 调 int 版,add(1.5, 2.5) 调 double 版
