• <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 小烏龜 閱讀(960) 評論(0)  編輯 收藏 引用 所屬分類: C&C++
            久久精品国产久精国产一老狼| 一本一本久久aa综合精品| 999久久久国产精品| 欧洲性大片xxxxx久久久| 精品久久久久久久久免费影院| 久久成人国产精品| 久久亚洲国产精品123区| 久久精品国产亚洲AV高清热| 国产精品亚洲美女久久久| 久久国产免费直播| 久久99国产一区二区三区| 亚洲成色WWW久久网站| 久久精品国产一区二区三区不卡| 亚洲伊人久久大香线蕉综合图片| 精品无码人妻久久久久久| 国产成年无码久久久久毛片| 久久笫一福利免费导航 | 91久久精品视频| 亚洲午夜久久久影院| 日产久久强奸免费的看| 精品午夜久久福利大片| 久久久久人妻精品一区| 久久久黄色大片| 伊人久久大香线蕉综合5g| 精品久久久无码中文字幕| 久久国产免费观看精品| 久久精品夜夜夜夜夜久久| 亚洲AV日韩AV天堂久久| 99久久综合国产精品免费| 香蕉久久永久视频| 香蕉99久久国产综合精品宅男自 | 一本久久知道综合久久| 亚洲精品第一综合99久久| 久久午夜无码鲁丝片午夜精品| 久久国产精品波多野结衣AV| 久久国产三级无码一区二区| 久久精品亚洲精品国产欧美| 久久天天躁狠狠躁夜夜av浪潮| 日韩欧美亚洲综合久久影院Ds| 久久se精品一区二区影院 | 伊人久久成人成综合网222|