Share in operator in c++

lyngocisaac

New member
## trong toán tử trong C ++

Toán tử trong C ++ là một toán tử Unary kiểm tra xem một phần tử có mặt trong một thùng chứa hay không.Nó có cú pháp sau:

`` `C ++
Element_type trong <tavyer_type> (container_object);
`` `

Ở đâu:

* `Element_type` là loại phần tử cần được kiểm tra.
* `container_type` là loại container.
* `container_object` là một đối tượng của loại` container_type`.

Toán tử trong trả về giá trị boolean, cho biết liệu phần tử có mặt trong thùng chứa hay không.Nếu phần tử có mặt, toán tử trả về `true`;Nếu không, nó trả về `false`.

Ví dụ: mã sau kiểm tra xem phần tử `" Xin chào "` có mặt trong vectơ `v`:

`` `C ++
#include <Istream>
#include <Vector>

sử dụng không gian tên STD;

int main () {
Vector <String> V = {"Hello", "World", "Goodbye"};

if ("xin chào" trong v) {
cout << "Phần tử \" Hello \ "có mặt trong vectơ."<< Endl;
} khác {
cout << "Phần tử \" Hello \ "không có trong vectơ."<< Endl;
}

trả lại 0;
}
`` `

Đầu ra:

`` `
Phần tử "xin chào" có mặt trong vector.
`` `

Toán tử trong có thể được sử dụng với bất kỳ loại container nào, bao gồm vectơ, danh sách, bộ và bản đồ.Tuy nhiên, toán tử chỉ hoạt động với các container hỗ trợ toán tử `[]`.

## hashtags

* #C ++
* #Operators
* #hộp đựng
* #Cấu trúc dữ liệu
* #Programming
=======================================
## In Operator in C++

The in operator in C++ is a unary operator that tests whether an element is present in a container. It has the following syntax:

```c++
element_type in <container_type> (container_object);
```

where:

* `element_type` is the type of the element to be tested.
* `container_type` is the type of the container.
* `container_object` is an object of type `container_type`.

The in operator returns a boolean value, which indicates whether the element is present in the container. If the element is present, the operator returns `true`; otherwise, it returns `false`.

For example, the following code tests whether the element `"hello"` is present in the vector `v`:

```c++
#include <iostream>
#include <vector>

using namespace std;

int main() {
vector<string> v = {"hello", "world", "goodbye"};

if ("hello" in v) {
cout << "The element \"hello\" is present in the vector." << endl;
} else {
cout << "The element \"hello\" is not present in the vector." << endl;
}

return 0;
}
```

Output:

```
The element "hello" is present in the vector.
```

The in operator can be used with any type of container, including vectors, lists, sets, and maps. However, the operator only works with containers that support the `[]` operator.

## Hashtags

* #C++
* #Operators
* #containers
* #data Structures
* #Programming
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top