Translations of this page?:

String 演算子

Syntax:

    #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 charT* s, const string& s2 );
    string operator+( charT c, const string& s2 );
    string operator+( const string& s1, const charT* s );
    string operator+( const string& s1, charT c );
    string& operator+=(const string& append);
    string& operator+=(const charT* append);
    string& operator+=(const charT  append);
    ostream& operator<<( ostream& os, const string& s );
    istream& operator>>( istream& is, string& s );
    string& operator=( const string& s );
    string& operator=( const charT* s );
    string& operator=( charT ch );
    charT& operator[]( size_type index );
    const charT& operator[]( size_type index ) const;
C++ strings can be compared and assigned with the standard comparison
operators: ==, !=, <=, >=, <, >, and =. Performing a comparison or assigning
one string to another takes linear time.

C++ 文字列(string) は、標準の比較演算子 (==, !=, <=, >=, <, >) と = 演算子によって、比較と代入(assign)が可能です。 ある文字列から別の文字列への比較や代入にかかる計算量は 線形時間(linear time) です。

Two strings are equal if:

- Their size is the same, and
- Each member in location i in one string is equal to the the member in location i in the other string.

二つの文字列は次の場合に等しいです:

  1. サイズが等しい
  2. すべての i について、 片方の文字列の i 番目のメンバが、他方の文字列の i 番目のメンバと等しい
Comparisons among strings are done lexicographically.

文字列の比較は lexicographically に行われます。

In addition to the normal container operators, strings can also be concatenated
with the + operator and fed to the C++ I/O stream classes with the << and >>
operators.

通常のコンテナ演算子に加えて、文字列は + 演算子による結合と、<<, >> 演算しによる C++ I/O stream classes への送受信が可能です。 (訳者メモ: feed を送受信と訳して良いか?)

For example, the following code concatenates two strings and displays the
result:

たとえば、次のコードは二つの文字列を結合してその結果を表示します:

   string s1 = "Now is the time...";
   string s2 = "for all good men...";
   string s3 = s1 + s2;
   cout << "s3 is " << s3 << endl;
Furthermore, strings can be assigned values that are other strings, character
arrays, or even single characters. The following code is perfectly valid:

加えて、文字列への代入は文字列から以外にも、文字の配列や単一の文字からも可能です。 次のコードは perfectly valid です。

   char ch = 'N';
   string s;
   s = ch;
Individual characters of a string can be examined with the [] operator, which
runs in constant time.

文字列の中の各文字は [] 演算子で参照できます。これは 定数時間(constant time) です。

Related Topics: c_str, compare, data

 
• • • SitemapRecent changesRSScc