[ Web Proxy ]
URL:
Viewing: http://pl.cppreference.com/cpp/string/basic_string/operator_cmp [Back]  [Original]

Operatory stringw cppreference.com
cppreference.com
Przestrzenie nazw
Warianty

Operatory stringw

Z cppreference.com

Skadnia:

    #include <string>
    bool operator==(const string& c1, const string& c2);
    bool operator!=(const string& c1, const string& c2);
    bool operator<(const string& c1, const string& c2);
    bool operator>(const string& c1, const string& c2);
    bool operator<=(const string& c1, const string& c2);
    bool operator>=(const string& c1, const string& c2);
    string operator+(const string& s1, const string& s2 );
    string operator+(const char* s, const string& s2 );
    string operator+( char c, const string& s2 );
    string operator+( const string& s1, const char* s );
    string operator+( const string& s1, char c );
    basic_string& operator+=(const basic_string& append);
    basic_string& operator+=(const char* append);
    basic_string& operator+=(const char  append);
    ostream& operator<<( ostream& os, const string& s );
    istream& operator>>( istream& is, string& s );
    string& operator=( const string& s );
    string& operator=( const char* s );
    string& operator=( char ch );
    char& operator[]( size_type index );

Stringi C++ mog by porwnywane i przypisywane za pomoc standardowych operatorw porwnania:

    • ==**, **!=**, **<=**, **>=**, **<**, **>** oraz **=**.

Porwnywanie lub przypisywanie stringw ma liniow zoono czasow.

Dwa stringi s rwne, jeli:

  1. Ich rozmiar jest taki sam oraz
  2. Kady element na pozycji i w pierwszym stringu jest rwny elementowi na pozycji i w drugim stringu.

Porwnywanie stringw przebiega leksykograficznie.

Poza normalnymi operatorami do pracy z tym pojemnikiem, stringi mog by take czone za pomoc operatora **+** oraz wstawiane do Strumieni I/O C++ przy uyciu operatorw **<<** oraz **>>**.

Przykad: nastpujcy fragment kodu czy dwa stringi i wywietla rezultat:

   string s1 = "Niezly ";
   string s2 = "hardkor";
   string s3 = s1 + s2;
   cout << "s3 is " << s3 << endl;

Co wicej, stringom mona przypisywa wartoci innych stringw, tablice znakw lub te pojedyncze znaki. Poniszy kod jest cakowicie poprawny:

   char ch = 'N';
   string s;
   s = ch;

Do pojedynczych znakw w stringu mona si odnosi za pomoc operatora **[]**, ktry dziaa w staym czasie.

Powizane tematy: c_str, compare, data


Web Proxy Viewer  |  New URL  |  Original Page