• <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++
            色播久久人人爽人人爽人人片AV| 久久99热国产这有精品| 久久久国产亚洲精品| 亚洲国产精品无码久久一线| 久久久久久亚洲AV无码专区| 伊人久久综合热线大杳蕉下载| 国产精品免费久久久久电影网| 亚洲国产精品狼友中文久久久| 久久综合久久自在自线精品自 | 99久久精品免费| 青青草国产97免久久费观看| 亚洲va久久久噜噜噜久久狠狠| 久久综合综合久久97色| 国产精品99久久久久久宅男小说| 欧美伊香蕉久久综合类网站| 无码精品久久一区二区三区| 日本久久久久久中文字幕| 7777久久久国产精品消防器材| 国产精品女同一区二区久久| 久久香综合精品久久伊人| 久久亚洲国产精品123区| 精品一区二区久久| 伊人久久综合无码成人网| 久久久久亚洲精品天堂久久久久久 | 久久久久人妻一区二区三区| 国内精品伊人久久久久网站| 久久精品人成免费| 99久久国产精品免费一区二区| 久久免费观看视频| 99久久国产综合精品五月天喷水 | 久久精品视频免费| 亚洲AV成人无码久久精品老人| 一本大道久久东京热无码AV| 久久电影网| 久久91精品综合国产首页| 色综合久久中文综合网| 久久精品一区二区国产| 久久精品中文字幕久久| 成人资源影音先锋久久资源网| 久久久久亚洲AV片无码下载蜜桃| 久久亚洲中文字幕精品一区|