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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲欧美日韩精品久久亚洲区 | 久久精品中文无码资源站| 久久久精品国产亚洲成人满18免费网站 | 欧美一区二区三区久久综| 久久99热只有频精品8| 国产叼嘿久久精品久久| 久久精品卫校国产小美女| 久久人人爽人人爽人人AV| 2021最新久久久视精品爱| 99久久99久久| 少妇熟女久久综合网色欲| 99国产精品久久| 一本一本久久aa综合精品| 久久久久久久久久免免费精品| 精品久久久久中文字幕日本| 2021国产精品久久精品| 韩国三级中文字幕hd久久精品| 久久亚洲欧美国产精品| 久久人人青草97香蕉| 色天使久久综合网天天| 成人久久久观看免费毛片| 伊人久久大香线蕉av一区| 午夜精品久久影院蜜桃| 国产免费福利体检区久久 | 久久久午夜精品| 久久国产成人午夜aⅴ影院| 久久精品国内一区二区三区| 国产69精品久久久久777| 亚洲欧美成人综合久久久| 亚洲伊人久久成综合人影院 | 色婷婷久久综合中文久久一本| 精品久久久久久国产| 亚洲午夜无码久久久久小说| 久久精品亚洲男人的天堂| 99热都是精品久久久久久| 99久久精品免费| 国产精品久久久久乳精品爆| 婷婷久久综合九色综合98| 亚洲国产精品热久久| 91亚洲国产成人久久精品网址| 91精品无码久久久久久五月天|