• <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精品久久久久久动态图| 国内精品久久久久久久涩爱| 久久久久国产精品三级网 | 精品国产日韩久久亚洲| 伊人精品久久久久7777| 无码国产69精品久久久久网站| 97r久久精品国产99国产精| 久久九九免费高清视频| 亚洲AV无码一区东京热久久 | 91精品国产综合久久香蕉 | 久久99热国产这有精品| 久久伊人精品青青草原日本| 亚洲AV无码久久精品成人| 久久最新精品国产| 亚洲AV无一区二区三区久久| 国产毛片久久久久久国产毛片| 99久久国产综合精品女同图片| 久久精品成人国产午夜| 亚洲精品乱码久久久久久自慰| 丁香久久婷婷国产午夜视频| 色欲av伊人久久大香线蕉影院| 国内精品久久久久久久coent| 无码人妻少妇久久中文字幕蜜桃| 精品久久综合1区2区3区激情| 久久国产乱子伦免费精品| 97香蕉久久夜色精品国产| 久久影视综合亚洲| 精品视频久久久久| 品成人欧美大片久久国产欧美...| 国产毛片欧美毛片久久久| 久久亚洲电影| 一本大道久久a久久精品综合| 久久亚洲AV成人无码国产| 亚洲国产欧美国产综合久久| 亚洲精品高清一二区久久| 久久久无码精品午夜| 国产亚州精品女人久久久久久| 国产精品视频久久久| 久久99热狠狠色精品一区| 99久久精品国产高清一区二区|