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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            无码人妻久久一区二区三区蜜桃| 亚洲AV无码一区东京热久久 | 午夜视频久久久久一区| 久久精品国产第一区二区| 亚洲综合久久夜AV | 久久精品国产亚洲av日韩| 久久精品国产网红主播| 久久精品国产福利国产琪琪| 亚洲va久久久噜噜噜久久天堂| 久久99免费视频| 久久精品国产亚洲αv忘忧草 | 要久久爱在线免费观看| 亚洲精品乱码久久久久久按摩| 国产成人精品久久综合| 久久精品国产亚洲αv忘忧草| 久久亚洲欧美日本精品| 久久AV高潮AV无码AV| 久久99精品久久久久久野外| 亚洲午夜久久久久久久久电影网| 国产—久久香蕉国产线看观看| 色欲综合久久中文字幕网| 色综合久久中文字幕综合网| 91久久精品国产免费直播| 狠狠色丁香久久婷婷综合五月 | 人妻丰满AV无码久久不卡| 久久天天日天天操综合伊人av| A狠狠久久蜜臀婷色中文网| 伊人久久久AV老熟妇色| 婷婷久久综合| 欧美伊人久久大香线蕉综合 | 久久精品卫校国产小美女| 美女久久久久久| 久久精品国产72国产精福利| 国产亚洲欧美成人久久片| 久久人爽人人爽人人片AV| 漂亮人妻被黑人久久精品| 久久精品国产久精国产一老狼| 热久久最新网站获取| 中文字幕精品久久| 狠狠综合久久AV一区二区三区| 一本色道久久88精品综合 |