• <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)  編輯 收藏 引用

            導航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            精品国产青草久久久久福利| 国内精品久久久久影院老司| 2021久久国自产拍精品| 91精品国产高清91久久久久久| 久久国产亚洲精品麻豆| 久久WWW免费人成—看片| 97精品依人久久久大香线蕉97| 国内精品久久久久影院优| 久久影视国产亚洲| 久久人人爽人人爽人人AV| 九九久久精品国产| 久久久亚洲欧洲日产国码aⅴ| 久久精品www| 蜜臀久久99精品久久久久久小说| 久久国产高清一区二区三区| 日本强好片久久久久久AAA| 久久精品国产99久久久香蕉| 久久久久99精品成人片欧美| 久久性精品| 久久男人AV资源网站| 国产精品毛片久久久久久久 | 国产99久久精品一区二区| 久久久网中文字幕| 国产69精品久久久久9999| 久久婷婷五月综合97色| 久久久久久精品免费免费自慰| 国产精品青草久久久久福利99| 国产成人久久精品激情 | 亚洲综合久久综合激情久久 | 国产成人香蕉久久久久| 国产V综合V亚洲欧美久久| 青草国产精品久久久久久| 囯产极品美女高潮无套久久久| 久久男人中文字幕资源站| 久久精品一区二区影院| 狠狠人妻久久久久久综合| 久久精品国产秦先生| av午夜福利一片免费看久久| 久久久精品国产sm调教网站 | 男女久久久国产一区二区三区| 久久精品卫校国产小美女|