ขั้นตอนการสร้างและรันโปรแกรม C++
1. สร้าง Source File
สร้างไฟล์ source.cpp ด้วย text editor:
#include <iostream>
int main() {
std::cout << "Hello world";
}
2. Compile ด้วย GCC (g++)
$ cd 'C:/Users/Dell/Documents' # ไปที่โฟลเดอร์ source $ g++ -o myprogram source.cpp # compile สร้าง executable myprogram
3. Run โปรแกรม
$ ./myprogram
คำอธิบายคำสั่ง
g++- GNU C++ compiler-o myprogram- ชื่อไฟล์ executable outputsource.cpp- ไฟล์ source code./myprogram- รัน executable (Linux/Mac) บน Windows ใช้myprogram.exe
Compilers ยอดนิยม
- GCC (g++): https://gcc.gnu.org/
- Clang: https://clang.llvm.org/get_started.html
- Visual C++ Community: https://visualstudio.microsoft.com/vs/cplusplus/
- Online: tutorialspoint.com/compile_cpp_online.php