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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久精品久久久久特色影视| 久久综合综合久久狠狠狠97色88| 久久成人永久免费播放| 久久九九免费高清视频| 国产精品久久久久久久app| 久久久老熟女一区二区三区| 2021少妇久久久久久久久久| 久久国产精品二国产精品| 奇米影视7777久久精品人人爽| 久久w5ww成w人免费| 久久久久99精品成人片牛牛影视| 亚洲综合精品香蕉久久网| 青青青国产精品国产精品久久久久 | 亚洲国产精品成人久久蜜臀 | 伊人久久大香线蕉亚洲五月天| 热99re久久国超精品首页| 久久人人爽人人人人爽AV| 精品久久久久中文字| www.久久精品| 久久精品国产亚洲AV无码麻豆 | 亚洲精品久久久www| 国产精品99久久久久久www| 久久久久99精品成人片试看| 精品伊人久久久| 国内精品久久久久影院亚洲| 国内精品久久久久影院网站| 国产亚洲精品美女久久久| 成人午夜精品无码区久久| 伊人情人综合成人久久网小说| 99热都是精品久久久久久| 一级做a爱片久久毛片| 精品久久久久久久无码| 久久亚洲欧美国产精品| 亚洲精品乱码久久久久久久久久久久 | 青青草原综合久久大伊人精品| 国产成人久久AV免费| 国产精品久久久久久福利漫画| 久久久久人妻精品一区二区三区| 亚洲AV无一区二区三区久久| 无遮挡粉嫩小泬久久久久久久| 无码AV波多野结衣久久|