• <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 閱讀(379) 評論(0)  編輯 收藏 引用

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            青青青青久久精品国产| 色偷偷888欧美精品久久久| 久久综合色区| 久久这里的只有是精品23| 无码久久精品国产亚洲Av影片| 久久久久久久97| 久久午夜无码鲁丝片午夜精品| 久久亚洲欧美国产精品| 精品久久久久久无码人妻热 | 久久这里只精品国产99热| 欧美日韩精品久久久久| 久久精品麻豆日日躁夜夜躁| 午夜精品久久久久久| 日本道色综合久久影院| 五月丁香综合激情六月久久| 开心久久婷婷综合中文字幕| 国产精品久久永久免费| 久久亚洲精品中文字幕| 国产成人精品三上悠亚久久| 亚洲国产综合久久天堂| 99久久夜色精品国产网站| 久久国产精品77777| 99久久精品国产一区二区| 久久婷婷五月综合成人D啪| 国内精品久久久久影院网站| 久久国产精品久久国产精品| 人妻无码αv中文字幕久久琪琪布| 久久免费视频1| 亚洲午夜无码AV毛片久久| 久久久久99精品成人片| 久久久久亚洲AV无码去区首| 久久久久18| 无码八A片人妻少妇久久| 久久综合亚洲色HEZYO社区| 国内精品伊人久久久影院| 久久精品国产亚洲AV忘忧草18| 一本色道久久88综合日韩精品 | 久久久久久久综合综合狠狠| 91视频国产91久久久| 久久国产精品国产自线拍免费| 国产综合久久久久|