Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) operator!=

 

operator!= is the operator to determine if two instances are different.

 

The following code uses operator!= to determine that three is not equal to four:

 

#include <iostream>

int main()
{
  if (3 != 4) std::cout << "Three is not equal to four" << std::endl;
}

 

operator!= is encapsulated by the functor std::not_equal_to.

 

 

 

 

 

Advice

 

 

 

 

 

 

 

References

 

  1. Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 2.4, Common Programming Error 2.2. page 32: 'Reversing the order of the pair of symbols in the operators !=, >= and < (by writing them as =!, => and =< respectively) is normally a syntax error. In some cases, writing != as =! will not be a syntax error, but almost certainly will be a logic error that has an effect at execution time.'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict