GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::operator!= - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. string
  3. basic_string
  4. operator!=

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

function template
<string>

std::operator!=

namespace std {
  // operator==により、以下の演算子が使用可能になる (C++20)
  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++98
  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>
  constexpr bool
    operator!=(const basic_string<CharT, Traits, Allocator>& a,
               const basic_string<CharT, Traits, Allocator>& b) noexcept; // (1) C++20


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

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

概要

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

参照

  • LWG2064 - More noexcept issues in basic_string
  • P0980R1 Making std::string constexpr
  • P1614R2 The Mothership has Landed
    • C++20での三方比較演算子の追加と、関連する演算子の自動導出
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.