• <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>

            Dain

            寫出一個可以工作的程序并不夠

            統(tǒng)計

            留言簿(3)

            積分與排名

            良師益友

            閱讀排行榜

            評論排行榜

            string和int間的類型轉換

            int 轉換 string
            string ?int2str( int ?num)
            {
            ???
            if (num? == ? 0 )
            ??????
            return ? " 0 " ;
            ???
            ???
            string ?str? = ? "" ;
            ???
            int ?num_? = ?num? > ? 0 ? ? ?num?:? - 1 ? * ?num;

            ???
            while (num_)
            ???
            {
            ??????str?
            = ?( char )(num_? % ? 10 ? + ? 48 )? + ?str;
            ??????num_?
            /= ? 10 ;
            ??? }


            ???
            if (num? < ? 0 )
            ??????str?
            = ? " - " ? + ?str;

            ???
            return ?str;
            }
            string 轉換 int
            int ?str2int( string ?str)
            {
            ???
            int ?i,len? = ?str.size(),num? = ? 0 ;

            ??? i?
            = ? 0 ;???
            ???
            if (str[ 0 ]? == ? ' - ' )
            ??????i?
            = ? 1 ;
            ???
            ???
            while (i? < ?len)
            ???
            {
            ??????num?
            = ?num? * ? 10 ? + ?( int )(str[i]? - ? ' 0 ' );
            ??????i
            ++ ;
            ??? }


            ???
            if (str[ 0 ]? == ? ' - ' )
            ??????num?
            *= ? - 1 ;

            ???
            return ?num;
            }

            string和int間是可以自己寫函數(shù)實現(xiàn)類型轉換的,但是string和double就不太方便了,stirng轉換double可以自定義函數(shù)實現(xiàn),但是,double轉換string就需要使用庫函數(shù)了,如sprintf

            posted on 2006-12-10 13:05 Dain 閱讀(13589) 評論(10)  編輯 收藏 引用 所屬分類: 算法

            評論

            # re: string和int間的類型轉換 2006-12-10 19:09 cloudsea

            不錯呀!
            以后要用就用您的了
            3x  回復  更多評論   

            # re: string和int間的類型轉換 2006-12-12 11:48 hanson

            itoa atoi 不可以用么  回復  更多評論   

            # re: string和int間的類型轉換 2006-12-12 12:03 Dain

            當然可以阿
            還有其他的庫函數(shù)也可以的sscanf
            @hanson
              回復  更多評論   

            # re: string和int間的類型轉換 2006-12-12 12:05 Dain

            也可以自己寫函數(shù)實現(xiàn)阿
            @hanson
              回復  更多評論   

            # re: string和int間的類型轉換 2006-12-20 16:37 子彈

            stringstream 也是不錯的東東
            :)  回復  更多評論   

            # re: string和int間的類型轉換 2007-01-04 09:56 Dain

            Implementing itoa function is a popular interview question. Here’s one implementation from SAP.

            char *itoa(int value)
            {
            int count, /* number of characters in string */
            i, /* loop control variable */
            sign; /* determine if the value is negative */
            char *ptr, /* temporary pointer, index into string */
            *string, /* return value */
            *temp; /* temporary string array */

            count = 0;
            if ((sign = value) < 0) /* assign value to sign, if negative */
            { /* keep track and invert value */
            value = -value;
            count++; /* increment count */
            }

            /* allocate INTSIZE plus 2 bytes (sign and NULL) */
            temp = (char *) malloc(INTSIZE + 2);
            if (temp == NULL)
            {
            return(NULL);
            }
            memset(temp,'\0', INTSIZE + 2);

            string = (char *) malloc(INTSIZE + 2);
            if (string == NULL)
            {
            return(NULL);
            }
            memset(string,'\0', INTSIZE + 2);
            ptr = string; /* set temporary ptr to string */

            /*--------------------------------------------------------------------+
            | NOTE: This process reverses the order of an integer, ie: |
            | value = -1234 equates to: char [4321-] |
            | Reorder the values using for {} loop below |
            +--------------------------------------------------------------------*/
            do {
            *temp++ = value % 10 + '0'; /* obtain modulus and or with '0' */
            count++; /* increment count, track iterations*/
            } while (( value /= 10) >0);

            if (sign < 0) /* add '-' when sign is negative */
            *temp++ = '-';

            *temp-- = '\0'; /* ensure null terminated and point */
            /* to last char in array */

            /*--------------------------------------------------------------------+
            | reorder the resulting char *string: |
            | temp - points to the last char in the temporary array |
            | ptr - points to the first element in the string array |
            +--------------------------------------------------------------------*/
            for (i = 0; i < count; i++, temp--, ptr++)
            {
            memcpy(ptr,temp,sizeof(char));
            }

            return(string);
            }
              回復  更多評論   

            # re: string和int間的類型轉換 2007-12-30 08:53 sdgsdg

            http://video-porno-casalinghe.fatte-tun.info
            http://xxx-latinas.fatte-tun.info
            http://foto-donna-mature-porca.fatte-tun.info
            http://video-porno-gay-gratis-cellulare.gradis-tun.info
            http://gnocca-sventrate.fatte-tun.info
            http://belle-anziane-in-collant.fatte-tun.info
            http://transattive-transex.fatte-tun.info
            http://lottatrici-erotiche.fatte-tun.info
            http://ragazza-giovane-fanno-sesso.fatte-tun.info
            http://piace-far-sesso-tovolo-nia-cucino.gradis-tun.info
            http://sex-sesso-porno-gay.fatte-tun.info
            http://negra-sesso-negra-troia-negra-culo-sborra-pompino.fatte-tun.info
            http://immagine-cazzo-enorme-gratis.sculaccia-tun.info
            http://culo-donna-formosi.fatte-tun.info
            http://coppie-amatoriale.sculaccia-tun.info
            http://porno-diciotenni.fatte-tun.info
            http://mutandine-igienica-incontinenza.fatte-tun.info
            http://gay-twinks-teen-young.gradis-tun.info
            http://porno-lesbian-ass-finger-ring-clip-movie.sculaccia-tun.info
            http://sexishop-salerno.sculaccia-tun.info
            http://erotica-tour-2006.gradis-tun.info
            http://sfondami-il-culo.fatte-tun.info
            http://sexy-bar-la-tv-piccante.sculaccia-tun.info
            http://porno-gay-sado.fatte-tun.info
            http://video-sborrata-gay-gratis.fatte-tun.info
            http://vecchia-arrapata.fatte-tun.info  回復  更多評論   

            # re: string和int間的類型轉換 2008-09-28 10:23 xx

            怎么非的自己造一遍輪子呢  回復  更多評論   

            # re: string和int間的類型轉換 2009-05-03 12:51 創(chuàng)意產(chǎn)品

            學習了,謝謝  回復  更多評論   

            # re: string和int間的類型轉換 2009-07-23 11:50 楊全

            謝謝啦!@Dain
              回復  更多評論   

            国产精品久久网| 性做久久久久久久| 久久精品国产精品亚洲精品| 狠狠色丁香婷婷久久综合不卡| 国产成人香蕉久久久久| 女同久久| 国内精品久久久久久99| 99热都是精品久久久久久| 久久久久人妻精品一区三寸蜜桃| 久久天天躁狠狠躁夜夜avapp| 亚洲精品无码久久千人斩| 女人香蕉久久**毛片精品| 久久精品国产一区二区三区不卡| 亚洲国产欧洲综合997久久| 国产精品久久久久影院嫩草| 久久精品无码一区二区app| 日韩精品久久无码人妻中文字幕| 精品久久人人妻人人做精品| 久久综合88熟人妻| 无码乱码观看精品久久| 久久99国产亚洲高清观看首页 | 国产精品久久久久久一区二区三区| 国产一区二区精品久久凹凸 | 一本一道久久精品综合| 久久狠狠爱亚洲综合影院| 国内精品欧美久久精品| 久久人人妻人人爽人人爽| 中文字幕久久亚洲一区| 久久国产视频网| 久久青草国产手机看片福利盒子| 亚洲日韩中文无码久久| 亚洲国产成人久久笫一页| 精品久久久久久久久久久久久久久 | 无码超乳爆乳中文字幕久久| 香蕉99久久国产综合精品宅男自| 9999国产精品欧美久久久久久| 无码人妻久久久一区二区三区| 久久久久免费精品国产| 久久精品国产99国产精品导航| 国产69精品久久久久观看软件| 性高朝久久久久久久久久|