• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            小烏龜

            在夢想的道路上還能走多遠

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::


            看一段簡單的代碼:

            int main()

                
            string s;
                s 
            += 'a';    
                s 
            += "bc"
                cout 
            << "s: " << s << endl;
                    
                cout 
            << endl;
                system(
            "Pause");
                
            return 0;
            }

            對不?當然對的!參看basic_string.h中的源碼:

                  basic_string&
                  
            operator+=(const basic_string& __str) { return this->append(__str); }

                  
            /**
                   *  @brief  Append a C string.
                   *  @param s  The C string to append.
                   *  @return  Reference to this string.
                   
            */
                  basic_string
            &
                  
            operator+=(const _CharT* __s) { return this->append(__s); }

                  
            /**
                   *  @brief  Append a character.
                   *  @param s  The character to append.
                   *  @return  Reference to this string.
                   
            */
                  basic_string
            &
                  
            operator+=(_CharT __c) { return this->append(size_type(1), __c); }

            下面的代碼對不?

                string s1;    
                s1 
            = 'a';    // = 也定義了右邊的值為字符的情況 
                cout << "s1: " << s1 << endl;
                s1 
            = "bc";
                cout 
            << "s1: " << s1 << endl;

            看源碼!

                  basic_string&
                  
            operator=(const basic_string& __str) 
                  { 
                
            this->assign(__str); 
                
            return *this;
                  }

                  
            /**
                   *  @brief  Copy contents of @a s into this string.
                   *  @param  s  Source null-terminated string.
                   
            */
                  basic_string
            &
                  
            operator=(const _CharT* __s) 
                  { 
                
            this->assign(__s); 
                
            return *this;
                  }

                  
            /**
                   *  @brief  Set value to string of length 1.
                   *  @param  c  Source character.
                   *
                   *  Assigning to a character makes this string length 1 and
                   *  (*this)[0] == @a c.
                   
            */
                  basic_string
            &
                  
            operator=(_CharT __c) 
                  { 
                
            this->assign(1, __c); 
                
            return *this;
                  }

            下面的呢

                string s2("u");
                s2 
            = 'j' + s2;        
                     cout 
            << "s2: " << s2 << endl;    
                s2 
            = s2 + 'n';
                cout 
            << "s2: " << s2 << endl;
                s2 
            = "jin " + s2;
                cout 
            << "s2: " << s2 << endl;
                s2 
            = s2 + " xia";
                cout 
            << "s2: " << s2 << endl;

            還是源碼!

            // operator+
              /**
               *  @brief  Concatenate two strings.
               *  @param lhs  First string.
               *  @param rhs  Last string.
               *  @return  New string with value of @a lhs followed by @a rhs.
               
            */
              template
            <typename _CharT, typename _Traits, typename _Alloc>
                basic_string
            <_CharT, _Traits, _Alloc>
                
            operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
                      
            const basic_string<_CharT, _Traits, _Alloc>& __rhs)
                {
                  basic_string
            <_CharT, _Traits, _Alloc> __str(__lhs);
                  __str.append(__rhs);
                  
            return __str;
                }

              
            /**
               *  @brief  Concatenate C string and string.
               *  @param lhs  First string.
               *  @param rhs  Last string.
               *  @return  New string with value of @a lhs followed by @a rhs.
               
            */
              template
            <typename _CharT, typename _Traits, typename _Alloc>
                basic_string
            <_CharT,_Traits,_Alloc>
                
            operator+(const _CharT* __lhs,
                      
            const basic_string<_CharT,_Traits,_Alloc>& __rhs);

              
            /**
               *  @brief  Concatenate character and string.
               *  @param lhs  First string.
               *  @param rhs  Last string.
               *  @return  New string with @a lhs followed by @a rhs.
               
            */
              template
            <typename _CharT, typename _Traits, typename _Alloc>
                basic_string
            <_CharT,_Traits,_Alloc>
                
            operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);

              
            /**
               *  @brief  Concatenate string and C string.
               *  @param lhs  First string.
               *  @param rhs  Last string.
               *  @return  New string with @a lhs followed by @a rhs.
               
            */
              template
            <typename _CharT, typename _Traits, typename _Alloc>
                inline basic_string
            <_CharT, _Traits, _Alloc>
                
            operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
                     
            const _CharT* __rhs)
                {
                  basic_string
            <_CharT, _Traits, _Alloc> __str(__lhs);
                  __str.append(__rhs);
                  
            return __str;
                }

              
            /**
               *  @brief  Concatenate string and character.
               *  @param lhs  First string.
               *  @param rhs  Last string.
               *  @return  New string with @a lhs followed by @a rhs.
               
            */
              template
            <typename _CharT, typename _Traits, typename _Alloc>
                inline basic_string
            <_CharT, _Traits, _Alloc>
                
            operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
                {
                  typedef basic_string
            <_CharT, _Traits, _Alloc>    __string_type;
                  typedef typename __string_type::size_type        __size_type;
                  __string_type __str(__lhs);
                  __str.append(__size_type(
            1), __rhs);
                  
            return __str;
                }

            也許,最好的資料就是看看頭文件或者源碼!


            posted on 2008-11-23 16:14 小烏龜 閱讀(957) 評論(0)  編輯 收藏 引用 所屬分類: C&C++
            久久久久久久尹人综合网亚洲 | 国产成人精品综合久久久久| 精品久久人人妻人人做精品 | 久久无码AV中文出轨人妻| 久久毛片一区二区| 91精品国产91久久综合| 久久e热在这里只有国产中文精品99| 久久久久国产成人精品亚洲午夜| 99久久做夜夜爱天天做精品| 777米奇久久最新地址| 久久综合给合综合久久| 久久精品国产精品亚洲毛片| 久久99精品国产99久久6| 伊人久久大香线蕉av一区| 成人a毛片久久免费播放| 人人妻久久人人澡人人爽人人精品| 国产美女久久精品香蕉69| 久久久免费观成人影院| 青青青伊人色综合久久| 亚洲国产另类久久久精品小说 | 国内精品久久久久影院亚洲| 久久久久久狠狠丁香| 久久久女人与动物群交毛片| 久久夜色精品国产噜噜亚洲a| 久久久久久久综合日本亚洲| 亚洲成色WWW久久网站| 亚洲欧美精品一区久久中文字幕| 久久久青草久久久青草| 久久国产精品无码HDAV| 无码国内精品久久人妻| 亚洲中文字幕无码久久综合网| 久久免费观看视频| 久久久久人妻精品一区三寸蜜桃| 国产午夜精品久久久久免费视| 人妻久久久一区二区三区| 国产精品中文久久久久久久| 色偷偷88欧美精品久久久| 久久久久99精品成人片三人毛片| 久久久久久久亚洲精品| 久久精品无码一区二区三区日韩 | 久久激情五月丁香伊人|