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

             

            [導(dǎo)入]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 閱讀(379) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            2020最新久久久视精品爱| 久久精品国产精品亚洲人人| 99久久综合国产精品免费| 伊人久久一区二区三区无码| 日本欧美久久久久免费播放网| 99久久国产热无码精品免费 | www.久久热| 久久亚洲AV无码西西人体| 77777亚洲午夜久久多人| 欧美精品一区二区精品久久| 亚洲精品tv久久久久| 精品免费tv久久久久久久| 久久久久亚洲AV片无码下载蜜桃| 久久99国产亚洲高清观看首页| 亚洲另类欧美综合久久图片区| 好久久免费视频高清| 亚洲精品无码久久久影院相关影片 | 亚洲午夜久久久久妓女影院 | 欧美va久久久噜噜噜久久| 久久久久久国产精品无码下载| 国产精品久久午夜夜伦鲁鲁| 欧美成a人片免费看久久| 青青草原综合久久大伊人精品| 久久久久国产精品熟女影院| 久久性精品| 久久综合成人网| 精品乱码久久久久久夜夜嗨| 99久久免费国产特黄| 亚洲成色WWW久久网站| 久久无码国产专区精品| 一本大道久久东京热无码AV | 久久精品免费观看| 97久久精品无码一区二区| 久久久久AV综合网成人| 久久综合综合久久综合| 99精品国产99久久久久久97| 成人综合久久精品色婷婷| 国产69精品久久久久久人妻精品| 中文字幕人妻色偷偷久久| 久久国产色av免费看| 亚洲国产精品久久电影欧美|