<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ##實戰c++中的string系列--string的連接(+= or append or push_back) string的連接也是經常用到的,string重載了一些運算符:? 首先看一看重載+運算符,用于串聯兩個字符串對象:? 源碼: ~~~ template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator> operator+( const basic_string<CharType, Traits, Allocator>& _Left, const basic_string<CharType, Traits, Allocator>& _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator> operator+( const basic_string<CharType, Traits, Allocator>& _Left, const CharType* _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator> operator+( const basic_string<CharType, Traits, Allocator>& _Left, const CharType _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator> operator+( const CharType* _Left, const basic_string<CharType, Traits, Allocator>& _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator> operator+( const CharType _Left, const basic_string<CharType, Traits, Allocator>& _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator>&& operator+( const basic_string<CharType, Traits, Allocator>& _Left, const basic_string<CharType, Traits, Allocator>&& _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator>&& operator+( const basic_string<CharType, Traits, Allocator>&& _Left, const basic_string<CharType, Traits, Allocator>& _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator>&& operator+( const basic_string<CharType, Traits, Allocator>&& _Left, const basic_string<CharType, Traits, Allocator>&& _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator>&& operator+( const basic_string<CharType, Traits, Allocator>&& _Left, const CharType *_Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator>&& operator+( const basic_string<CharType, Traits, Allocator>&& _Left, CharType _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator>&& operator+( const CharType *_Left, const basic_string<CharType, Traits, Allocator>&& _Right ); template<class CharType, class Traits, class Allocator> basic_string<CharType, Traits, Allocator>&& operator+( CharType _Left, const basic_string<CharType, Traits, Allocator>&& _Rig ~~~ 所以使用時,注意事項: ~~~ #include<iostream> #include<string> int main() { std::string my_str = "holiday"; std::string my_str_add = "error" + "error";//錯誤 std::string my_str_add2 = my_str + "right"; std::string my_str_add3 = my_str + "right" + "right"; std::string my_str_add4 = "right" + my_str; std::string my_str_add5 = "error" + "error" + my_str;//錯誤 return 0; } ~~~ 下面開始正題!? **+=**? ****將字符追加到字符串**** ~~~ basic_string<CharType, Traits, Allocator>& operator+=( value_type _Ch ); basic_string<CharType, Traits, Allocator>& operator+=( const value_type* _Ptr ); basic_string<CharType, Traits, Allocator>& operator+=( const basic_string<CharType, Traits, Allocator>& _Right ); ~~~ **append**? ****添加字符為字符串的末尾**** ~~~ basic_string<CharType, Traits, Allocator>& append( const value_type* _Ptr ); basic_string<CharType, Traits, Allocator>& append( const value_type* _Ptr, size_type _Count ); basic_string<CharType, Traits, Allocator>& append( const basic_string<CharType, Traits, Allocator>& _Str, size_type _Off, size_type _Count ); basic_string<CharType, Traits, Allocator>& append( const basic_string<CharType, Traits, Allocator>& _Str ); basic_string<CharType, Traits, Allocator>& append( size_type _Count, value_type _Ch ); template<class InputIterator> basic_string<CharType, Traits, Allocator>& append( InputIterator _First, InputIterator _Last ); basic_string<CharType, Traits, Allocator>& append( const_pointer _First, const_pointer _Last ); basic_string<CharType, Traits, Allocator>& append( const_iterator _First, const_iterator _Last ); ~~~ 有多個重載函數,因此多種使用方法: ~~~ string str1a ( "Hello " ); const char *cstr1a = "Out There "; str1a.append ( cstr1a ); string str1b ( "Hello " ); const char *cstr1b = "Out There "; str1b.append ( cstr1b , 3 ); string str1c ( "Hello " ), str2c ( "Wide World " ); str1c.append ( str2c , 5 , 5 ); string str1d ( "Hello " ), str2d ( "Wide " ), str3d ( "World " ); str1d.append ( str2d ); str1d += str3d; string str1e ( "Hello " ); str1e.append ( 4 , '!' ); string str1f ( "Hello " ), str2f ( "Wide World " ); str1f.append ( str2f.begin ( ) + 5 , str2f.end ( ) - 1 ); ~~~ **push_back**? ****將元素添加到該字符串的末尾**** ~~~ void push_back( value_type _Ch ); ~~~ 這里需要注意的是,以下代碼是錯誤的: ~~~ my_str.push_back("123");//錯誤 my_str.push_back('1');//ok ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看