# Compiling and running

1. ติดตั้ง Visual code studio ตามระบบปฏิบัติการที่ใช้ (for window ถ้าใช้ WSL, for Debian ถ้าใช้ Ubuntu)

{% content-ref url="../development-environment-preparation/visual-studio-code" %}
[visual-studio-code](https://docs.aic-eec.com/c-c++-for-embedded-programming/development-environment-preparation/visual-studio-code)
{% endcontent-ref %}

&#x20;   \- สำหรับผู้ที่ใช้ Windows ทำตามขั้นตอนในลิ้งค์ทั้งหมดและทำการ [เชื่อมต่อกับ wsl](https://app.gitbook.com/@aic-ecc/s/docs/~/drafts/-MP28eGkXwMKIkmcSmXp/c-c++-for-embedded-programming/c-c++-environment-preparation/virtual-studio-code-wsl)\
&#x20;   \- สำหรับผู้ที่ใช้ Ubuntu ทำตามขั้นตอน 1,2

&#x20;  2\. เปิด Virtual code studio ขึ้นมาทำการสร้างไฟล์ .cpp ขึ้นมาตามขั้นตอนนี้\
&#x20;   2.1 ไปที่แถบเมนูของโปรแกรม Virtual studio code ที่ file เลือก New File \
&#x20;   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;
}
```

\
&#x20;  2.3 ไปที่แถบเมนู เปิด terminal เลือก New terminal จะแสดงหน้า terminal ดังภาพด้านล่าง

![](https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MClo3nC-1US0rbK8Qau%2F-MP2Ci_aR8qjz3SJWRbF%2F-MP2Dq2CWUm_uTara0Y3%2Fimage.png?alt=media\&token=e62229a4-36e1-456e-9585-a4be99fd0395)

&#x20;  2.4 พิมพ์คำสั่งลงใน terminal ดังนี้&#x20;

```
g++ hello_world.cpp -o hello
ls
./hello
```

![ภาพแสดงผลการรันโปรแกรม](https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MClo3nC-1US0rbK8Qau%2F-MP2DtqO76BHn1b4upgo%2F-MP2E9zk_SGsl16EP5CC%2Fimage.png?alt=media\&token=9bf51687-0c52-48f3-867f-9bcaefd5edff)
