Share c++ experimental source location

philong569

New member
## C ++ Vị trí nguồn thử nghiệm

[Liên kết đến bài viết tham khảo]

Vị trí nguồn thử nghiệm C ++ là một tính năng mới trong ngôn ngữ C ++ cho phép bạn chỉ định vị trí nguồn của một đoạn mã cụ thể.Điều này có thể hữu ích để gỡ lỗi hoặc theo dõi các lỗi.

Để sử dụng vị trí nguồn thử nghiệm C ++, bạn cần thêm cờ trình biên dịch `-fexperimental-source-location`.Điều này sẽ cho phép tính năng và cho phép bạn sử dụng hàm `__builtin_source_location ()` để có được vị trí nguồn của một đoạn mã cụ thể.

Hàm `__builtin_source_location ()` Trả về một đối tượng `Sourcelocation`, chứa các thông tin sau:

* Tên tệp nơi mã được đặt.
* Số dòng nơi mã được đặt.
* Số cột nơi đặt mã.

Bạn có thể sử dụng thông tin này để gỡ lỗi mã của bạn hoặc để theo dõi các lỗi.Ví dụ: bạn có thể sử dụng hàm `__builtin_source_location ()` để in ra vị trí nguồn của một thông báo lỗi cụ thể.

Dưới đây là một ví dụ về cách sử dụng vị trí nguồn thử nghiệm C ++:

`` `C ++
#include <Istream>

int main () {
// Nhận vị trí nguồn của chức năng này.
Vị trí sourcelocation = __builtin_source_location ();

// In ra tên tệp, số dòng và số cột.
std :: cout << "Tệp:" << vị trí.file << std :: endl;
std :: cout << "dòng:" << vị trí.line << std :: endl;
std :: cout << "cột:" << vị trí.column << std :: endl;

trả lại 0;
}
`` `

## hashtags

* C ++
* C ++ 17
* Các tính năng thử nghiệm
* Vị trí nguồn
* Gỡ lỗi
=======================================
## C++ Experimental Source Location

[Link to reference article]

C++ Experimental Source Location is a new feature in the C++ language that allows you to specify the source location of a particular piece of code. This can be useful for debugging or for tracking down errors.

To use C++ Experimental Source Location, you need to add the `-fexperimental-source-location` compiler flag. This will enable the feature and allow you to use the `__builtin_source_location()` function to get the source location of a particular piece of code.

The `__builtin_source_location()` function returns a `SourceLocation` object, which contains the following information:

* The file name where the code was located.
* The line number where the code was located.
* The column number where the code was located.

You can use this information to debug your code or to track down errors. For example, you could use the `__builtin_source_location()` function to print out the source location of a particular error message.

Here is an example of how to use C++ Experimental Source Location:

```c++
#include <iostream>

int main() {
// Get the source location of this function.
SourceLocation location = __builtin_source_location();

// Print out the file name, line number, and column number.
std::cout << "File: " << location.file << std::endl;
std::cout << "Line: " << location.line << std::endl;
std::cout << "Column: " << location.column << std::endl;

return 0;
}
```

## Hashtags

* C++
* C++17
* Experimental features
* Source location
* Debugging
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top