Compiling and running
Create your own C/C++ program and run it on your OS.
- 1.ติดตั้ง Visual code studio ตามระบบปฏิบัติการที่ใช้ (for window ถ้าใช้ WSL, for Debian ถ้าใช้ Ubuntu)
- สำหรับผู้ที่ใช้ Windows ทำตามขั้นตอนในลิ้งค์ทั้งหมดและทำการ เชื่อมต่อกับ wsl
- สำหรับผู้ที่ใช้ Ubuntu ทำตามขั้นตอน 1,2
2. เปิด Virtual code studio ขึ้นมาทำการสร้างไฟล์ .cpp ขึ้นมาตามขั้นตอนนี้
2.1 ไปที่แถบเมนูของโปรแกรม Virtual studio code ที่ file เลือก New File
2.2 Copy โค้ดไปใส่ แล้วกด Ctrl+S เพื่อทำการ save ไฟล์ชื่อว่า “hello_world.cpp”
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
2.3 ไปที่แถบเมนู เปิด terminal เลือก New terminal จะแสดงหน้า terminal ดังภาพด้านล่าง

2.4 พิมพ์คำสั่งลงใน terminal ดังนี้
g++ hello_world.cpp -o hello
ls
./hello

ภาพแสดงผลการรันโปรแกรม
Last modified 1mo ago