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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国内精品人妻无码久久久影院导航| 免费精品国产日韩热久久| 亚洲va久久久噜噜噜久久| 亚洲国产精品久久电影欧美| 午夜人妻久久久久久久久| 久久九九全国免费| 伊人色综合九久久天天蜜桃| 伊人精品久久久久7777| 性色欲网站人妻丰满中文久久不卡| 国产精品久久久久久福利漫画 | 国产精品免费久久| 久久久这里只有精品加勒比| 国产精品久久久久9999| 久久精品国产久精国产一老狼| 青青国产成人久久91网| 亚洲中文久久精品无码| 欧美与黑人午夜性猛交久久久| 国产精品美女久久久m| 亚洲精品国产第一综合99久久| 国产精品久久久久久福利69堂| 亚洲午夜久久久久久久久电影网| 精品久久久无码中文字幕| 久久久中文字幕| 久久99热只有频精品8| 亚洲精品乱码久久久久66| 久久这里的只有是精品23| 久久综合九色欧美综合狠狠| 国产综合免费精品久久久| 欧美黑人又粗又大久久久| 精品伊人久久久| 中文精品久久久久人妻| 久久亚洲AV无码西西人体| 91久久精品视频| 99久久成人18免费网站| 久久不射电影网| 国产精品99久久久久久宅男| 91精品国产高清久久久久久国产嫩草 | 久久久久久九九99精品| 亚洲va久久久噜噜噜久久天堂| 99久久无色码中文字幕人妻| 模特私拍国产精品久久|