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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久福利青草精品资源站免费 | 久久99精品九九九久久婷婷| 婷婷久久综合九色综合98| 国产精品久久久久久| 亚洲欧洲中文日韩久久AV乱码| 久久综合狠狠综合久久| 久久99精品国产麻豆婷婷| 久久久免费精品re6| 色综合久久88色综合天天 | 97久久天天综合色天天综合色hd| 亚洲国产成人久久综合野外 | 天天久久狠狠色综合| 久久久久波多野结衣高潮| 国产免费久久精品99久久| 久久午夜羞羞影院免费观看| 国产99久久久国产精品小说| 99久久精品国产一区二区| 69久久精品无码一区二区| 国产色综合久久无码有码| 亚洲а∨天堂久久精品| 国产精品伦理久久久久久| 91精品国产乱码久久久久久| 久久精品欧美日韩精品| 久久狠狠爱亚洲综合影院| 久久99热这里只有精品66| 亚洲国产天堂久久久久久| 亚洲国产成人乱码精品女人久久久不卡| 久久精品麻豆日日躁夜夜躁| 婷婷伊人久久大香线蕉AV| 无码AV中文字幕久久专区| 精品久久久无码人妻中文字幕| 一本色道久久88综合日韩精品| 伊人久久大香线蕉综合网站| 国产精品美女久久福利网站| 久久这里只精品99re66| 囯产精品久久久久久久久蜜桃 | 久久人妻少妇嫩草AV蜜桃| 色综合久久久久综合99| 久久精品国产精品亚洲精品| 久久久精品2019免费观看| 久久精品水蜜桃av综合天堂 |