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

             

            [導(dǎo)入]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)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久涩综合| 精品久久久无码人妻中文字幕豆芽| 国产精品视频久久| 97精品国产97久久久久久免费| 88久久精品无码一区二区毛片 | 伊人色综合久久天天| 久久精品国产精品亚洲人人 | 婷婷久久综合九色综合九七| 性做久久久久久久久久久| 人妻无码久久一区二区三区免费| 91麻精品国产91久久久久| 亚洲人成电影网站久久| 91久久精一区二区三区大全| 免费精品国产日韩热久久| 久久精品国产99国产电影网| 久久午夜福利无码1000合集| 久久r热这里有精品视频| 国产精品久久久久蜜芽| 久久激情亚洲精品无码?V| 久久精品国产久精国产思思 | 亚洲va中文字幕无码久久| 国产视频久久| 青青草原综合久久| 国产成人精品白浆久久69| 亚洲日韩中文无码久久| 精品久久久一二三区| 国内精品久久久久久中文字幕| 久久精品国产亚洲AV高清热| 久久99热这里只有精品国产| 理论片午午伦夜理片久久 | 国内精品久久久久影院亚洲| 久久精品无码免费不卡| 久久这里只精品国产99热| 久久国产精品99精品国产| 久久国产精品无码HDAV| 国产精品无码久久久久久| 精品久久久久久无码专区| WWW婷婷AV久久久影片| 久久婷婷激情综合色综合俺也去 | 中文国产成人精品久久亚洲精品AⅤ无码精品| 亚洲国产成人久久精品影视|