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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲精品乱码久久久久久按摩| 亚洲国产成人久久一区WWW| 久久人人青草97香蕉| 久久久久亚洲国产| 久久精品国产久精国产果冻传媒| 中文无码久久精品| AV无码久久久久不卡网站下载| 色综合久久88色综合天天| 热综合一本伊人久久精品| 久久99精品久久久大学生| 亚洲国产精品久久| 久久99精品久久久大学生| 精品国产91久久久久久久| 亚洲精品乱码久久久久久蜜桃| 91精品国产乱码久久久久久| 欧美性大战久久久久久| 九九久久自然熟的香蕉图片| 亚洲精品美女久久久久99小说 | 99久久综合国产精品二区| 无码人妻少妇久久中文字幕| 国产精品天天影视久久综合网| 少妇久久久久久被弄到高潮 | 久久久久久青草大香综合精品| 成人综合久久精品色婷婷| 精品久久777| 麻豆成人久久精品二区三区免费| 精品久久久久久国产免费了| 久久99热只有频精品8| 亚洲国产日韩欧美综合久久| 久久99精品久久久久久| 久久久久波多野结衣高潮| 青青青伊人色综合久久| 久久99精品久久久久久hb无码| 久久精品无码专区免费| 日韩久久久久久中文人妻| 久久亚洲AV无码西西人体| 国产日韩欧美久久| 狠狠干狠狠久久| 久久这里只精品99re66| 久久精品综合一区二区三区| 欧美一区二区精品久久|