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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产真实乱对白精彩久久| 无码国内精品久久人妻麻豆按摩| 久久久精品人妻一区二区三区四 | 欧美久久久久久| 亚洲AV无码久久精品成人| 久久精品无码一区二区三区| 亚州日韩精品专区久久久| 久久A级毛片免费观看| 久久福利片| 国产一区二区精品久久| 国产精品中文久久久久久久| 国产高清国内精品福利99久久| 国产精品99久久久精品无码| 精品久久久久久久中文字幕| 久久er99热精品一区二区| 一个色综合久久| 久久久久亚洲精品天堂久久久久久| 热re99久久精品国99热| 午夜精品久久久久| 久久中文精品无码中文字幕| 91精品国产91久久| 99麻豆久久久国产精品免费| 亚洲精品美女久久777777| 色婷婷综合久久久久中文字幕 | 久久综合综合久久狠狠狠97色88| 亚洲国产精品无码久久一线 | 麻豆精品久久久久久久99蜜桃| 国产精品九九久久免费视频 | 久久久久人妻一区精品果冻| 日韩精品久久久久久| 91精品国产高清久久久久久91| 国产精品国色综合久久| 国产精品久久久久jk制服| 国产精品久久久久久久| 国产精品久久国产精麻豆99网站 | www亚洲欲色成人久久精品| 四虎国产永久免费久久| 精品久久久久久久久久中文字幕| 久久精品国产亚洲Aⅴ香蕉 | 无码任你躁久久久久久老妇App| 久久青青草原精品国产不卡|