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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            欧美无乱码久久久免费午夜一区二区三区中文字幕 | 午夜不卡888久久| 精品久久久久久国产免费了| 久久人人妻人人爽人人爽| 办公室久久精品| 久久亚洲视频| 久久www免费人成精品香蕉| 久久狠狠色狠狠色综合| 欧美精品一区二区久久| 亚洲精品久久久www| 热re99久久精品国产99热| 久久婷婷久久一区二区三区| 中文成人无码精品久久久不卡| 久久99久久99精品免视看动漫| 国产精品久久久久9999| 久久天天躁狠狠躁夜夜不卡 | 91久久精品电影| 久久天天躁夜夜躁狠狠| 久久综合久久久| 久久九九久精品国产| 国产成人精品综合久久久久| 久久久无码精品亚洲日韩京东传媒 | 久久国产精品成人影院| 亚洲一区中文字幕久久| 青青草原精品99久久精品66| 久久久WWW成人免费精品| 精品综合久久久久久88小说 | 久久精品一区二区三区中文字幕| 久久精品人人做人人爽97| 国产亚洲综合久久系列| 久久久久国产精品熟女影院 | 色成年激情久久综合| 亚洲国产精品久久| 草草久久久无码国产专区| 国产成人精品久久亚洲高清不卡| 久久精品国产亚洲av麻豆色欲| 久久精品aⅴ无码中文字字幕不卡| 欧美丰满熟妇BBB久久久| 好属妞这里只有精品久久| 亚洲日本va午夜中文字幕久久| 久久久久国产精品熟女影院|