Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.6 KB

op_not_equal.md

File metadata and controls

65 lines (50 loc) · 1.6 KB

operator!=

  • string[meta header]
  • std[meta namespace]
  • function template[meta id-type]
namespace std {
  template <class CharT, class Traits, class Allocator>
  bool operator!=(const basic_string<CharT, Traits, Allocator>& a,
                  const basic_string<CharT, Traits, Allocator>& b); // (1) C++03

  template <class CharT, class Traits, class Allocator>
  bool operator!=(const basic_string<CharT, Traits, Allocator>& a,
                  const basic_string<CharT, Traits, Allocator>& b) noexcept; // (1) C++14

  template <class CharT, class Traits, class Allocator>
  bool operator!=(const CharT* a,
                  const basic_string<CharT, Traits, Allocator>& b); // (2)

  template <class CharT, class Traits, class Allocator>
  bool operator!=(const basic_string<CharT, Traits, Allocator>& a,
                  const CharT* b);                                  // (3)
}

概要

basic_stringオブジェクトの非等値比較を行う。

要件

  • (3) パラメータbが、Traits::length(b) + 1の要素数を持つCharT文字型の配列を指していること

戻り値

  • (1) !(a == b)
  • (2) b != a
  • (3) a.compare(b) != 0

#include <iostream>
#include <string>

int main()
{
  std::string a = "abc";
  std::string b = "abcd";

  if (a != b) {
    std::cout << "not equal" << std::endl;
  }
  else {
    std::cout << "equal" << std::endl;
  }
}

出力

not equal

参照