> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](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).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` 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>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
