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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            伊人久久大香线蕉精品| 欧美一级久久久久久久大| 欧美日韩精品久久久久| 国内精品伊人久久久影院| 99久久无色码中文字幕人妻| 精品免费久久久久久久| 久久99精品国产麻豆不卡| 成人综合久久精品色婷婷| 大伊人青草狠狠久久| 亚洲国产成人精品久久久国产成人一区二区三区综 | 青青热久久综合网伊人| 久久久久99精品成人片三人毛片 | 久久久精品人妻一区二区三区蜜桃| 亚洲精品无码久久久久| 婷婷久久综合九色综合98| 久久久久亚洲精品日久生情| 2020最新久久久视精品爱| 99久久精品免费看国产一区二区三区 | 国产精品综合久久第一页| 久久强奷乱码老熟女网站| 91性高湖久久久久| 久久久久亚洲AV片无码下载蜜桃 | 久久久久亚洲精品天堂| 理论片午午伦夜理片久久| 久久久久久久综合日本亚洲| 午夜久久久久久禁播电影| 思思久久99热免费精品6| 国产高潮久久免费观看| 久久亚洲精品中文字幕三区| 日本久久久久亚洲中字幕| 99精品国产免费久久久久久下载 | 99国产精品久久久久久久成人热| 精品久久久久成人码免费动漫| 国产午夜电影久久| 91久久精品国产91性色也| 久久精品一区二区| 99久久中文字幕| 亚洲国产精品久久久久网站 | 久久中文字幕人妻熟av女| 国产一区二区久久久| 中文字幕无码久久久|