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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久人妻一区精品性色av| 久久久亚洲欧洲日产国码aⅴ| 欧美亚洲国产精品久久蜜芽| 久久精品国产91久久麻豆自制| 久久精品国产清自在天天线| 久久人人爽人人爽人人片AV高清| 久久久国产精品亚洲一区| 伊人久久大香线蕉影院95| 久久综合日本熟妇| 久久Av无码精品人妻系列| 国产成人精品久久亚洲高清不卡| 国产精品久久婷婷六月丁香| 大伊人青草狠狠久久| 成人综合久久精品色婷婷| 精品久久久久久无码专区不卡| 精品久久久久中文字幕一区| 亚洲精品乱码久久久久久蜜桃图片 | 久久这里只有精品18| 亚洲综合精品香蕉久久网97| 国产成人无码精品久久久性色| 777久久精品一区二区三区无码 | 91精品国产91久久久久久| 亚洲午夜久久久久久久久电影网| 国产精品VIDEOSSEX久久发布| 色综合久久无码中文字幕| 久久久久久久久66精品片| 国产69精品久久久久9999| 久久福利青草精品资源站免费| 免费久久人人爽人人爽av| 亚洲va久久久久| 久久久久久国产精品无码下载| 18岁日韩内射颜射午夜久久成人| 久久久久亚洲AV成人片| 亚洲狠狠婷婷综合久久蜜芽| 久久婷婷五月综合国产尤物app| 久久久久无码国产精品不卡| 99久久国产主播综合精品 | 久久夜色精品国产噜噜麻豆| 精品久久人人爽天天玩人人妻| 久久久久久久波多野结衣高潮| 亚州日韩精品专区久久久|