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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产精品一区二区久久精品涩爱| 亚洲精品乱码久久久久66| 国产精品成人久久久久三级午夜电影| 99久久精品免费国产大片| 久久精品国产精品亜洲毛片| 亚洲精品NV久久久久久久久久| 亚洲乱码中文字幕久久孕妇黑人 | 日本欧美国产精品第一页久久| 99久久国产宗和精品1上映| 久久九九有精品国产23百花影院| 无码国内精品久久人妻麻豆按摩| 国产精品美女久久久久网| 久久精品国产精品亚洲精品| 91久久九九无码成人网站| 国内精品久久久久久99蜜桃| 香蕉久久久久久狠狠色| 久久人妻少妇嫩草AV蜜桃| 久久99精品国产麻豆宅宅| 日韩人妻无码精品久久久不卡| 欧美激情精品久久久久久久| 久久99精品久久久久久秒播| 久久se精品一区二区| 国产午夜精品久久久久免费视| 久久久久久久久久久| 久久人人爽人人爽人人片AV麻烦| 久久人人超碰精品CAOPOREN | 久久久久亚洲av综合波多野结衣| 久久婷婷五月综合97色直播| 国产AⅤ精品一区二区三区久久| 久久不射电影网| 欧美精品一区二区精品久久| 99国产精品久久| 久久无码av三级| 精品久久久久久无码人妻热| 久久精品国产99久久久香蕉| 久久久久国产| 久久精品国产AV一区二区三区| 色偷偷久久一区二区三区| avtt天堂网久久精品| 国产香蕉97碰碰久久人人| 久久久精品国产Sm最大网站|