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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲国产精品无码久久久秋霞2 | 热久久最新网站获取| 久久e热在这里只有国产中文精品99 | 日本三级久久网| 亚洲乱码日产精品a级毛片久久| 亚洲AV日韩精品久久久久久久| 久久精品成人欧美大片| 久久99国产一区二区三区| 中文字幕无码av激情不卡久久| 99久久国产综合精品女同图片| 精品无码人妻久久久久久| 久久免费看黄a级毛片| 久久精品视频网| 久久99精品久久久久久久久久| 免费一级做a爰片久久毛片潮| 久久线看观看精品香蕉国产| 色综合久久久久综合99| 久久国产精品免费一区| 久久精品黄AA片一区二区三区| 久久精品人妻中文系列| 丁香五月综合久久激情| 一级做a爰片久久毛片16| MM131亚洲国产美女久久| 久久国内免费视频| 无码精品久久一区二区三区 | 久久有码中文字幕| 亚洲国产天堂久久综合网站| 伊人久久大香线蕉综合影院首页| 久久精品一区二区影院| 久久男人中文字幕资源站| 久久国产精品一国产精品金尊| 国产精品久久久久免费a∨| 欧洲国产伦久久久久久久| 亚洲国产精品一区二区久久| 精品免费久久久久久久| 久久久一本精品99久久精品88| 久久久久亚洲精品日久生情 | 久久黄色视频| 深夜久久AAAAA级毛片免费看| 久久久久久毛片免费看| 久久99精品国产麻豆婷婷|