operator!= (<string>)

测试,如果运算符左侧的字符串对象与右侧的字符串对象不等于。

template<class CharType, class Traits, class Allocator> 
   bool operator!=( 
      const basic_string<CharType, Traits, Allocator>& _Left, 
      const basic_string<CharType, Traits, Allocator>& _Right 
   ); 
template<class CharType, class Traits, class Allocator> 
   bool operator!=( 
      const basic_string<CharType, Traits, Allocator>& _Left, 
      const CharType *_Right 
   ); 
template<class CharType, class Traits, class Allocator> 
   bool operator!=( 
      const CharType *_Left, 
      const basic_string<CharType, Traits, Allocator>& _Right 
   );

参数

  • _Left
    用 . 式字符串或类型要比较的 basic_string 对象。

  • _Right
    用 . 式字符串或类型要比较的 basic_string 对象。

返回值

true,如果运算符左侧的字符串对象与右侧的字符串对象是不相等;字典。为 false

备注

在字符串对象之间的比较基于其字符一个字典成对地比较。 两个字符串相等,如果其字符数相同,而且它们的相应字符值相同。 否则为不相等。

示例

// string_op_ne.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   // Declaring an objects of type basic_string<char>
   string s1 ( "pluck" );
   string s2 ( "strum" );
   cout << "The basic_string s1 = " << s1 << "." << endl;
   cout << "The basic_string s2 = " << s2 << "." << endl;

   // Declaring a C-style string
   char *s3 = "pluck";
   cout << "The C-style string s3 = " << s3 << "." << endl;

   // First member function: comparison between left-side object
   // of type basic_string & right-side object of type basic_string
   if ( s1 != s2 )
      cout << "The strings s1 & s2 are not equal." << endl;
   else
      cout << "The strings s1 & s2 are equal." << endl;

   // Second member function: comparison between left-side object
   // of type basic_string & right-side object of C-syle string type
   if ( s1 != s3 )
      cout << "The strings s1 & s3 are not equal." << endl;
   else
      cout << "The strings s1 & s3 are equal." << endl;

   // Third member function: comparison between left-side object
   // of C-syle string type & right-side object of type basic_string
   if ( s3 != s2 )
      cout << "The strings s3 & s2 are not equal." << endl;
   else
      cout << "The strings s3 & s2 are equal." << endl;
}
  

要求

标头:< 字符串>

命名空间: std

请参见

参考

string::operator!=