<iostream>:std::cin 定義於此頭文件。using namespace std; 或寫全名 std::cin。g++ main.cpp -o main 默認鏈接 libstdc++,通常不需額外 -lstdc++。// main.cpp
#include <iostream>
int main() {
int x;
std::cin >> x;
std::cout << "You entered: " << x << std::endl;
return 0;
}
# 編譯
g++ main.cpp -o main -std=c++17
# 執行
./main
#include <iostream>。cin 定義為區域變數遮蔽。g++ -v main.cpp 查看鏈接命令是否包含 -lstdc++。