Share học c++ trên visual studio code

duyhanhtrandan

New member
## Tìm hiểu C ++ trên Visual Studio Code

[Hình ảnh của mã Visual Studio với tiện ích mở rộng C ++ được cài đặt]

Visual Studio Code là một trình soạn thảo mã mạnh mẽ và linh hoạt có thể được sử dụng cho nhiều ngôn ngữ lập trình, bao gồm C ++.Nó là nguồn miễn phí và mở, và nó có một cộng đồng người dùng và nhà phát triển lớn đóng góp cho sự phát triển của nó.

Bài viết này sẽ chỉ cho bạn cách bắt đầu với sự phát triển C ++ trong Visual Studio Code.Chúng tôi sẽ đề cập đến những điều cơ bản của việc cài đặt tiện ích mở rộng C ++, tạo một dự án mới và viết và biên dịch chương trình C ++ đầu tiên của bạn.

### Điều kiện tiên quyết

Trước khi bạn có thể bắt đầu phát triển mã C ++ trong mã Visual Studio, bạn sẽ cần cài đặt các mục sau:

* Mã Studio Visual
* Tiện ích mở rộng C ++ cho mã Visual Studio
* Trình biên dịch C ++ (Trình biên dịch Microsoft C ++ hoặc Bộ sưu tập trình biên dịch GNU)

### Cài đặt tiện ích mở rộng C ++

Để cài đặt tiện ích mở rộng C ++ cho mã Visual Studio, hãy mở ngăn Phần mở rộng (Ctrl+Shift+X) và tìm kiếm "C ++".Nhấp vào nút "Cài đặt" để cài đặt tiện ích mở rộng.

### Tạo một dự án mới

Khi tiện ích mở rộng C ++ được cài đặt, bạn có thể tạo một dự án mới.Để thực hiện việc này, nhấp vào menu "Tệp" và chọn "Mở thư mục".Điều hướng đến thư mục nơi bạn muốn tạo dự án của mình và nhấp vào "Chọn thư mục".

Visual Studio Code sẽ tạo một thư mục mới cho dự án của bạn và mở nó trong trình soạn thảo.Thư mục dự án sẽ chứa một tệp có tên là "main.cpp".Đây là tệp mà bạn sẽ viết mã C ++ của mình.

### viết và biên dịch chương trình C ++ đầu tiên của bạn

Để viết chương trình C ++ đầu tiên của bạn, hãy mở tệp "main.cpp" trong trình soạn thảo.Nhập mã sau vào tệp:

`` `C ++
#include <Istream>

int main () {
std :: cout << "Xin chào, thế giới!"<< std :: endl;
trả lại 0;
}
`` `

Để biên dịch chương trình của bạn, nhấn Ctrl+Shift+b.Mã Visual Studio sẽ biên dịch chương trình của bạn và xuất thông báo sau:

`` `
.
Liên kết C ++ thực thi hello.exe
`` `

Nếu phần biên dịch thành công, bạn sẽ thấy một tệp mới có tên là "Hello.exe" trong thư mục dự án.Đây là tệp thực thi cho chương trình của bạn.

Để chạy chương trình của bạn, bấm đúp vào tệp "Hello.exe".Bạn sẽ thấy đầu ra sau trong thiết bị đầu cuối:

`` `
Chào thế giới!
`` `

### Phần kết luận

Bài viết này đã chỉ cho bạn cách bắt đầu với sự phát triển C ++ trong Visual Studio Code.Bạn đã học được cách cài đặt tiện ích mở rộng C ++, tạo một dự án mới và viết và biên dịch chương trình C ++ đầu tiên của bạn.

Để biết thêm thông tin về phát triển C ++ trong mã Visual Studio, vui lòng tham khảo các tài nguyên sau:

* [Tài liệu mã Visual Studio] (Get Started with C++ on Linux in Visual Studio Code)
* [Tài liệu mở rộng C ++] (C/C++ - Visual Studio Marketplace)
* [Tài liệu trình biên dịch C ++] (Microsoft C/C++ Documentation)

## hashtags

* #C ++
* #Visual Studio Code
* #Programming
* #phát triển
* #tutorial
=======================================
## Learn C++ on Visual Studio Code

[Image of Visual Studio Code with the C++ extension installed]

Visual Studio Code is a powerful and versatile code editor that can be used for a variety of programming languages, including C++. It is free and open source, and it has a large community of users and developers who contribute to its development.

This article will show you how to get started with C++ development in Visual Studio Code. We will cover the basics of installing the C++ extension, creating a new project, and writing and compiling your first C++ program.

### Prerequisites

Before you can start developing C++ code in Visual Studio Code, you will need to install the following:

* Visual Studio Code
* The C++ extension for Visual Studio Code
* The C++ compiler (either the Microsoft C++ compiler or the GNU Compiler Collection)

### Installing the C++ extension

To install the C++ extension for Visual Studio Code, open the Extensions pane (Ctrl+Shift+X) and search for "C++". Click the "Install" button to install the extension.

### Creating a new project

Once the C++ extension is installed, you can create a new project. To do this, click the "File" menu and select "Open Folder". Navigate to the folder where you want to create your project and click "Select Folder".

Visual Studio Code will create a new folder for your project and open it in the editor. The project folder will contain a file called "main.cpp". This is the file where you will write your C++ code.

### Writing and compiling your first C++ program

To write your first C++ program, open the "main.cpp" file in the editor. Type the following code into the file:

```c++
#include <iostream>

int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
```

To compile your program, press Ctrl+Shift+B. Visual Studio Code will compile your program and output the following message:

```
[1/1] Building C++ object CMakeFiles/hello.dir/main.cpp.obj
Linking C++ executable hello.exe
```

If the compilation was successful, you will see a new file called "hello.exe" in the project folder. This is the executable file for your program.

To run your program, double-click the "hello.exe" file. You should see the following output in the terminal:

```
Hello, world!
```

### Conclusion

This article has shown you how to get started with C++ development in Visual Studio Code. You have learned how to install the C++ extension, create a new project, and write and compile your first C++ program.

For more information on C++ development in Visual Studio Code, please refer to the following resources:

* [Visual Studio Code documentation](https://code.visualstudio.com/docs/cpp/)
* [C++ extension documentation](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
* [C++ compiler documentation](https://docs.microsoft.com/en-us/cpp/)

## Hashtags

* #C++
* #Visual Studio Code
* #Programming
* #development
* #tutorial
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top