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

  1. เปิด Ubuntu ทำการ สร้าง folder ชื่อ “test_project” ด้วยคำสั่งดังนี้

mkdir test_project

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

2. เปิดโปรแกรม Virtual studio code

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

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

2.3 เลือก โฟลเดอร์ชื่อ test_project ที่เราได้สร้างจากขั้นตอนที่ 1

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

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

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

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

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University