# Compiling and running

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

{% content-ref url="/pages/-MNSeOAF67rgBiIU-Xvs" %}
[ติดตั้งโปรแกรม Visual Studio Code](/c-c++-for-embedded-programming/development-environment-preparation/visual-studio-code.md)
{% 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 ดังภาพด้านล่าง

![](/files/-MP2Dq2CWUm_uTara0Y3)

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

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

![ภาพแสดงผลการรันโปรแกรม](/files/-MP2E9zk_SGsl16EP5CC)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/principle-c-c++-programming/linux-os-lab-1-c-c++-code.-how-to-compile-and-run..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
