You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An alternative spelling for the **`!=`** operator.
15
14
16
15
## Syntax
17
16
@@ -21,34 +20,40 @@ An alternative to the **`!=`** operator.
21
20
22
21
## Remarks
23
22
24
-
The macro yields the operator **`!=`**.
23
+
C++:
24
+
- **`not_eq`** can be used as alternative to **`!=`**. The [`/permissive-`](../../build/reference/permissive-standards-conformance.md) or [`/Za`](../../build/reference/za-ze-disable-language-extensions.md) compiler option is required.
25
+
- Including `<iso646.h>` or `<ciso646>` is deprecated. You can use the alternative spelling without including any header files.
26
+
- There's no alternative spelling for **`==`**.
27
+
28
+
C:
29
+
- **`not_eq`** is an alternative spelling for **`!=`**. It is provided as a macro in `<iso646.h>`, which you must `#include`.
30
+
- There's no alternative spelling for **`==`**.
25
31
26
32
## Example
27
33
28
34
```cpp
29
-
// iso646_not_eq.cpp
30
35
// compile with: /EHsc
31
36
#include <iostream>
32
37
#include <iso646.h>
33
38
34
39
int main( )
35
40
{
36
-
using namespace std;
37
-
int a = 0, b = 1;
38
-
39
-
if (a != b)
40
-
cout << "a is not equal to b" << endl;
41
-
42
-
if (a not_eq b)
43
-
cout << "a is not equal to b" << endl;
41
+
int x = 1, y = 2;
42
+
43
+
// not_eq is available in C++ and C
44
+
// This example is for C++, so no header file is needed to use not_eq
45
+
// When compiling for C, #include <iso646.h> to use not_eq
46
+
if (x not_eq y)
47
+
{
48
+
std::cout << "Not equal\n";
49
+
}
44
50
}
45
51
```
46
52
47
53
```Output
48
-
a is not equal to b
49
-
a is not equal to b
54
+
Not equal
50
55
```
51
56
52
57
## Requirements
53
58
54
-
**Header:**\<iso646.h>
59
+
**Header:**`<iso646.h>` is necessary if you are compiling for C.
The binary equality operators compare their operands for strict equality or inequality.
17
+
The equal-to operator (**`==`**) returns **`true`** if both operands have the same value; otherwise **`false`**.\
18
+
The not-equal-to operator (**`!=`**) returns **`true`** if the operands don't have the same value; otherwise **`false`**.
19
19
20
-
The equality operators, equal to (**`==`**) and not equal to (**`!=`**), have lower precedence than the relational operators, but they behave similarly. The result type for these operators is **`bool`**.
21
-
22
-
The equal-to operator (**`==`**) returns **`true`** if both operands have the same value; otherwise, it returns **`false`**. The not-equal-to operator (**`!=`**) returns **`true`** if the operands don't have the same value; otherwise, it returns **`false`**.
23
-
24
-
## Operator keyword for !=
25
-
26
-
C++ specifies **`not_eq`** as an alternative spelling for **`!=`**. (There's no alternative spelling for **`==`**.) In C, the alternative spelling is provided as a macro in the \<iso646.h> header. In C++, the alternative spelling is a keyword; use of \<iso646.h> or the C++ equivalent \<ciso646> is deprecated. In Microsoft C++, the [`/permissive-`](../build/reference/permissive-standards-conformance.md) or [`/Za`](../build/reference/za-ze-disable-language-extensions.md) compiler option is required to enable the alternative spelling.
20
+
In C and C++, **`not_eq`** can be used as alternative to **`!=`**. For more information, see [`not-eq`](../c-runtime-library/reference/not-eq.md).
27
21
28
22
## Example
29
23
30
24
```cpp
31
-
// expre_Equality_Operators.cpp
32
-
// compile with: /EHsc
33
25
#include<iostream>
34
26
35
-
usingnamespacestd;
36
-
37
-
intmain() {
38
-
cout << boolalpha
39
-
<< "The true expression 3 != 2 yields: "
40
-
<< (3 != 2) << endl
41
-
<< "The false expression 20 == 10 yields: "
42
-
<< (20 == 10) << endl;
27
+
intmain()
28
+
{
29
+
int x = 1, y = 1, z = 2;
30
+
31
+
if (x == y)
32
+
{
33
+
std::cout << "Equal\n";
34
+
}
35
+
36
+
if (x != z)
37
+
{
38
+
std::cout << "Not equal\n";
39
+
}
43
40
}
44
41
```
45
42
46
-
Equality operators can compare pointers to members of the same type. In such a comparison, pointer-to-member conversions are performed. Pointers to members can also be compared to a constant expression that evaluates to 0.
0 commit comments