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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            97精品依人久久久大香线蕉97| 国产毛片久久久久久国产毛片| 久久毛片免费看一区二区三区| 久久91精品国产91久久户| 国产精品久久久久9999| 久久久WWW成人免费毛片| 亚洲欧洲中文日韩久久AV乱码| 婷婷综合久久中文字幕蜜桃三电影| 久久精品国产亚洲AV嫖农村妇女| 中文字幕成人精品久久不卡| 香蕉久久夜色精品国产2020| 国产91色综合久久免费| 久久亚洲av无码精品浪潮| 国产成人无码精品久久久性色| 精品国产福利久久久| 久久亚洲精品国产亚洲老地址 | 久久精品毛片免费观看| 91精品日韩人妻无码久久不卡| 麻豆av久久av盛宴av| 亚洲综合婷婷久久| 久久综合综合久久综合| 无码人妻少妇久久中文字幕| 久久久久久久99精品免费观看| 亚洲精品无码久久久久sm| 久久伊人五月天论坛| 国产 亚洲 欧美 另类 久久| 久久久久亚洲AV成人片| 日产精品久久久久久久| 精品无码久久久久久久动漫| 996久久国产精品线观看| 亚洲精品乱码久久久久久蜜桃图片| 久久久久无码国产精品不卡| 国产成人久久久精品二区三区 | 久久亚洲av无码精品浪潮| 亚洲国产成人久久综合一| 久久婷婷综合中文字幕| 久久久精品人妻一区二区三区蜜桃| 久久久亚洲精品蜜桃臀| 免费一级欧美大片久久网 | 久久久精品视频免费观看| 94久久国产乱子伦精品免费|