# การเชื่อมต่อ Virtual studio code เข้ากับ WSL

1. &#x20;เปิด Ubuntu ทำการ สร้าง folder ชื่อ “test\_project” ด้วยคำสั่งดังนี้

```
mkdir test_project
```

และ คำสั่ง ls เพื่อแสดงโฟล์ที่ได้สร้างไว้

![](https://paper-attachments.dropbox.com/s_8A1FED18EA21FC9C95036AEB616EAFA7245C9BB7CFEEC278232A34CCEF5C73AD_1606914351183_image.png)

2\. เปิดโปรแกรม Virtual studio code&#x20;

&#x20;     2.1 คลิ๊กตามภาพด้านล่าง

![หน้าต่างโปรแกรม VS Code](https://paper-attachments.dropbox.com/s_8A1FED18EA21FC9C95036AEB616EAFA7245C9BB7CFEEC278232A34CCEF5C73AD_1606912619525_Untitled.png)

&#x20;      2.2 เลือก Remote-wsl: Open Folder In WSL… ตามภาพด้านล่าง

![](https://paper-attachments.dropbox.com/s_8A1FED18EA21FC9C95036AEB616EAFA7245C9BB7CFEEC278232A34CCEF5C73AD_1606914884105_image.png)

&#x20;    2.3 เลือก โฟลเดอร์ชื่อ test\_project ที่เราได้สร้างจากขั้นตอนที่ 1&#x20;

![](https://paper-attachments.dropbox.com/s_8A1FED18EA21FC9C95036AEB616EAFA7245C9BB7CFEEC278232A34CCEF5C73AD_1606914915849_image.png)

&#x20;   2.4 ไปที่แถบเมนูของโปรแกรม Virtual studio code ที่ flie เลือก New Flie&#x20;

&#x20;   2.5 Copy โค้ดไปใส่ แล้วกด Ctrl+S เพื่อทำการ save ไฟล์ชื่อว่า “hello\_world.cpp”&#x20;

```
#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.6 ไปที่แถบเมนู เปิด terminal เลือก New terminal จะแสดงหน้า terminal ดังภาพด้านล่าง

![](https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MClo3nC-1US0rbK8Qau%2F-MNZ0euA3sOjjb8fpcjM%2F-MNZ4XrCoBzid5-TVBLt%2FehzvEYDM.png?alt=media\&token=2534926c-245e-4aa2-ba96-c42256a6e07a)

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

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

![ผลการรันโปรแกรม hello](https://paper-attachments.dropbox.com/s_8A1FED18EA21FC9C95036AEB616EAFA7245C9BB7CFEEC278232A34CCEF5C73AD_1606915954228_image.png)
