• <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精品国产麻豆| 精品久久久久久无码专区不卡| 国产精品热久久无码av| 激情五月综合综合久久69| 三级三级久久三级久久| 亚洲综合精品香蕉久久网| 996久久国产精品线观看| 久久亚洲欧洲国产综合| 亚洲av成人无码久久精品| 国产精品激情综合久久| 亚洲AV日韩精品久久久久| 国产精品99久久久久久宅男 | 伊人久久无码精品中文字幕| 四虎国产精品成人免费久久| 久久一日本道色综合久久| 精品综合久久久久久88小说| 99久久99久久精品国产片果冻| 精品永久久福利一区二区| 蜜桃麻豆www久久| 综合网日日天干夜夜久久| 久久精品免费大片国产大片| 亚洲国产美女精品久久久久∴| 91麻精品国产91久久久久| 亚洲中文字幕无码久久2020| 久久久久亚洲av成人无码电影 | 久久国产精品国产自线拍免费| 久久精品国产亚洲精品| 久久婷婷国产综合精品| 亚洲综合熟女久久久30p| 欧美日韩精品久久免费| 久久午夜无码鲁丝片午夜精品| 久久久久夜夜夜精品国产| 99久久夜色精品国产网站| 精品人妻伦九区久久AAA片69| 99久久精品费精品国产 | 奇米影视7777久久精品| 久久99热这里只有精品国产| 久久精品国产72国产精福利| 99久久综合狠狠综合久久|