• <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++ Programmer's Cookbook

            {C++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

            CSTRING類(不是我寫的)

            ////CSTRING.H
            // Dream House World Static Model
            #ifndef __CSTRING__
            #define __CSTRING__

            #include <iostream.h>

            class StringIndexOutOfBounds { };

            class CSTRING
            {
            public:
            CSTRING( const char *cstring = "" ); // Constructor
            CSTRING( const CSTRING & str ); // Copy constructor
            ~CSTRING( ) // Destructor
            { delete [ ] buffer; }

            const CSTRING & operator+= ( const int number ); // apend number
            const CSTRING & operator= ( const CSTRING & rhs ); // Copy
            const CSTRING & operator+=( const CSTRING & rhs ); // Append

            const char *c_str( ) const // Return C-style CSTRING
            { return buffer; }
            int length( ) const // Return CSTRING length
            { return strLength; }

            char operator[]( int k ) const; // Accessor operator[]
            char & operator[]( int k ); // Mutator operator[]

            enum { MAX_LENGTH = 1024 }; // Maximum length for input CSTRING

            private:
            char *buffer; // storage for characters
            int strLength; // length of CSTRING (# of characters)
            int bufferLength; // capacity of buffer
            };

            ostream & operator<<( ostream & out, const CSTRING & str ); // Output
            istream & operator>>( istream & in, CSTRING & str ); // Input
            istream & getline( istream & in, CSTRING & str ); // Read line

            bool operator==( const CSTRING & lhs, const CSTRING & rhs ); // Compare ==
            bool operator!=( const CSTRING & lhs, const CSTRING & rhs ); // Compare !=
            bool operator< ( const CSTRING & lhs, const CSTRING & rhs ); // Compare <
            bool operator<=( const CSTRING & lhs, const CSTRING & rhs ); // Compare <=
            bool operator> ( const CSTRING & lhs, const CSTRING & rhs ); // Compare >
            bool operator>=( const CSTRING & lhs, const CSTRING & rhs ); // Compare >=

            #endif // __CSTRING__
            ////////////////////////////////////////////////////////////////////
            //CSTRING.CPP
            // Dream House World Static Model
            #include <string.h>
            #include <stdio.h>
            #include "CSTRING.h"


            CSTRING::CSTRING( const char * cstring )
            {
            if( cstring == NULL )
            cstring = "";
            strLength = strlen( cstring );
            bufferLength = strLength + 1;
            buffer = new char[ bufferLength ];
            strcpy( buffer, cstring );
            }

            CSTRING::CSTRING( const CSTRING & str )
            {
            strLength = str.length( );
            bufferLength = strLength + 1;
            buffer = new char[ bufferLength ];
            strcpy( buffer,str.buffer );
            }

            const CSTRING & CSTRING::operator=( const CSTRING & rhs )
            {
            if( this != &rhs )
            {
            if( bufferLength < rhs.length( ) + 1 )
            {
            delete [ ] buffer;
            bufferLength = rhs.length( ) + 1;
            buffer = new char[ bufferLength ];
            }
            strLength = rhs.length( );
            strcpy( buffer, rhs.buffer );
            }
            return *this;
            }

            const CSTRING & CSTRING::operator+=( const CSTRING & rhs )
            {
            if( this == &rhs )
            {
            CSTRING copy( rhs );
            return *this += copy;
            }

            int newLength = length( ) + rhs.length( );
            if( newLength >= bufferLength )
            {
            bufferLength = 2 * ( newLength + 1 );

            char *oldBuffer = buffer;
            buffer = new char[ bufferLength ];
            strcpy( buffer, oldBuffer );
            delete [ ] oldBuffer;
            }

            strcpy( buffer + length( ), rhs.buffer );
            strLength = newLength;
            return *this;
            }

            const CSTRING & CSTRING::operator+=(const int number)
            {
            char temp[20];
            sprintf(temp,"%d",number);
            CSTRING num( temp );
            *this += num;
            return *this;
            }

            char & CSTRING::operator[ ]( int k )
            {
            if( k < 0 || k >= strLength )
            throw StringIndexOutOfBounds( );
            return buffer[ k ];
            }

            char CSTRING::operator[ ]( int k ) const
            {
            if( k < 0 || k >= strLength )
            throw StringIndexOutOfBounds( );
            return buffer[ k ];
            }

            ostream & operator<<( ostream & out, const CSTRING & str )
            {
            return out << str.c_str();
            }

            istream & operator>>( istream & in, CSTRING & str )
            {
            char buf[ CSTRING::MAX_LENGTH + 1 ];
            in >> buf;
            if( !in.fail( ) )
            str = buf;
            return in;
            }

            istream & getline( istream & in, CSTRING & str )
            {
            char buf[ CSTRING::MAX_LENGTH + 1 ];
            in.getline( buf, CSTRING::MAX_LENGTH );
            if( !in.fail( ) )
            str = buf;
            return in;
            }

            bool operator==( const CSTRING & lhs, const CSTRING & rhs )
            {
            return strcmp( lhs.c_str( ), rhs.c_str( ) ) == 0;
            }

            bool operator!=( const CSTRING & lhs, const CSTRING & rhs )
            {
            return strcmp( lhs.c_str( ), rhs.c_str( ) ) != 0;
            }

            bool operator<( const CSTRING & lhs, const CSTRING & rhs )
            {
            return strcmp( lhs.c_str( ), rhs.c_str( ) ) < 0;
            }

            bool operator<=( const CSTRING & lhs, const CSTRING & rhs )
            {
            return strcmp( lhs.c_str( ), rhs.c_str( ) ) <= 0;
            }

            bool operator>( const CSTRING & lhs, const CSTRING & rhs )
            {
            return strcmp( lhs.c_str( ), rhs.c_str( ) ) > 0;
            }

            bool operator>=( const CSTRING & lhs, const CSTRING & rhs )
            {
            return strcmp( lhs.c_str( ), rhs.c_str( ) ) >= 0;
            }



            posted on 2005-12-06 15:49 夢(mèng)在天涯 閱讀(1526) 評(píng)論(0)  編輯 收藏 引用 所屬分類: CPlusPlus

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計(jì)

            • 隨筆 - 461
            • 文章 - 4
            • 評(píng)論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1807518
            • 排名 - 5

            最新評(píng)論

            閱讀排行榜

            MM131亚洲国产美女久久| 91久久国产视频| 亚洲精品tv久久久久久久久久| 久久久精品久久久久久| 一本一道久久a久久精品综合| 国色天香久久久久久久小说| 伊人久久大香线蕉亚洲| 波多野结衣中文字幕久久| 久久乐国产精品亚洲综合| 99久久精品国产一区二区| 精品999久久久久久中文字幕| 久久久久久一区国产精品| 精品多毛少妇人妻AV免费久久| 精品久久久久久久无码| 久久精品亚洲乱码伦伦中文| 亚洲国产精品一区二区久久hs | 久久综合香蕉国产蜜臀AV| 青青草国产精品久久久久| 久久亚洲精品成人无码网站| 99久久国产主播综合精品| 久久久久久久久久久精品尤物| 天天爽天天爽天天片a久久网| 中文精品99久久国产 | 亚洲国产精品成人久久| 国产精品99久久精品爆乳| 久久国产精品无码一区二区三区| 亚洲性久久久影院| 久久精品国产亚洲Aⅴ香蕉| 久久中文骚妇内射| 午夜精品久久久久久久久| 性做久久久久久久久| 国产99久久久国产精免费| 久久精品黄AA片一区二区三区| 久久婷婷五月综合成人D啪| 久久亚洲AV无码西西人体| 国内精品伊人久久久久网站| 精品国产福利久久久| 伊人久久大香线蕉精品| 四虎国产永久免费久久| 久久精品不卡| 久久99热这里只频精品6|