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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久Av无码精品人妻系列| 亚洲一本综合久久| AV色综合久久天堂AV色综合在| 国产精品久久自在自线观看| 无码人妻久久一区二区三区蜜桃| 中文字幕日本人妻久久久免费 | 亚洲欧洲久久久精品| 午夜精品久久久久久久久| 欧美午夜A∨大片久久| 精品一区二区久久| 色综合久久无码五十路人妻| 久久久精品日本一区二区三区 | 久久精品国产日本波多野结衣| 久久不见久久见免费视频7| 久久久午夜精品| 久久久精品日本一区二区三区 | 97超级碰碰碰碰久久久久| 亚洲狠狠婷婷综合久久久久 | 久久久精品免费国产四虎| 中文无码久久精品| 久久久精品人妻一区二区三区蜜桃| 精品国产婷婷久久久| 国产成人精品久久免费动漫| 久久久久久久亚洲Av无码| 77777亚洲午夜久久多人| 亚洲国产精品成人AV无码久久综合影院| 国产精品久久久久影院色| 久久综合九色综合97_久久久| 精品国产一区二区三区久久| 国产精品久久毛片完整版| 国产精品福利一区二区久久| 久久精品中文字幕无码绿巨人 | 亚洲AV无码久久| 无码人妻久久一区二区三区免费 | 亚洲精品乱码久久久久久不卡| 精品99久久aaa一级毛片| 久久国产成人午夜aⅴ影院| 伊人色综合久久天天网| 精品综合久久久久久97| 久久久久久久97| 人人狠狠综合久久亚洲婷婷|