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

            Robin Chow's C++ Blog

             

            [導入]Convert from string to int

            The methods: 1) From the C standard library, using atoi:
            #include 
            #include 
            std::string text = "152"; 
            int number = std::atoi( text.c_str() ); 
            if (errno == ERANGE) //that may be std::errno 
            { 
            //the number was too big/small to store completely, number is either LONG_MAX or LONG_MIN 
            } 
            else if (errno == ????) 
            //maybe EINVAL? not sure, man page dosn't seem to say... 
            //other possibilities are E2BIG and EDOM (or ERANGE maybe again)... 
            //but I'd vote for EINVAL 
            { 
            //unable to convert to a number 
            }
            2) From the C++ standard library, using strstream:
            #include 
            #include 
            std::string text = "152"; 
            int number; 
            std::istringstream ss( text ); 
            ss >> number; 
            if (! ss.good()) 
            { 
            //something happened 
            }
            3) From the Boost library, using lexical_cast:
            #include 
            #include  
            
            try 
            { 
            std::string text = "152"; 
            int number = boost::lexical_castint >( text ); 
            } 
            catch( const boost::bad_lexical_cast & ) 
            { 
            //unable to convert 
            }

            文章來源:http://my.donews.com/robinchow/2007/04/17/post-070417-111701-329/

            posted on 2007-10-23 20:45 Robin Chow 閱讀(377) 評論(0)  編輯 收藏 引用

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久人人爽人人爽人人片AV麻豆 | 国产精品久久久久久福利漫画| 久久综合九色综合久99| 久久亚洲精品成人AV| 久久国产精品成人影院| 久久精品国产亚洲精品| 久久亚洲高清综合| 99久久99久久精品国产片| 亚洲国产成人精品女人久久久| 7国产欧美日韩综合天堂中文久久久久 | 久久久久亚洲精品日久生情| 亚洲第一永久AV网站久久精品男人的天堂AV | 久久久久久久91精品免费观看| 久久精品国产99国产精品导航 | 亚洲一区精品伊人久久伊人| 久久精品18| 少妇精品久久久一区二区三区| 91超碰碰碰碰久久久久久综合| 亚洲国产精品久久久久久| 伊人丁香狠狠色综合久久| 污污内射久久一区二区欧美日韩| 久久综合伊人77777| 日批日出水久久亚洲精品tv| 少妇熟女久久综合网色欲| 99久久人人爽亚洲精品美女| 精品久久久久久无码免费| 久久精品a亚洲国产v高清不卡| 久久成人永久免费播放| 中文字幕亚洲综合久久菠萝蜜| 国产一区二区三区久久| 亚洲国产精品无码久久一线| jizzjizz国产精品久久| 伊人久久大香线蕉av一区| 亚洲AⅤ优女AV综合久久久| 久久夜色精品国产网站| 国产呻吟久久久久久久92| 97久久精品无码一区二区| 成人综合久久精品色婷婷| 久久精品a亚洲国产v高清不卡| 亚洲欧美久久久久9999 | 亚洲午夜精品久久久久久app|