• <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热成人精品热久久669| 久久96国产精品久久久| 999久久久无码国产精品| 精品久久无码中文字幕| 久久久久久亚洲精品无码| 亚洲国产成人久久综合碰| 国内精品久久久久久99蜜桃| 久久一日本道色综合久久| 久久成人影院精品777| 国产免费久久久久久无码| 久久人人爽人人爽人人片AV不 | 国产精品中文久久久久久久| 久久水蜜桃亚洲av无码精品麻豆| 99久久久精品| 久久久久久综合网天天| 色综合色天天久久婷婷基地| 人妻无码αv中文字幕久久| 久久99精品久久久久久秒播| 国产精品久久久久久久| 午夜精品久久影院蜜桃| 国产亚洲美女精品久久久| 亚洲AV日韩精品久久久久| 精品综合久久久久久97| 大蕉久久伊人中文字幕| 久久一日本道色综合久久| 久久99这里只有精品国产| 狠狠久久综合| 久久天堂电影网| 久久91精品国产91久久户| 色综合久久久久综合体桃花网| 麻豆国内精品久久久久久| 四虎国产精品免费久久| 热99re久久国超精品首页| 色综合久久久久综合体桃花网| 亚洲七七久久精品中文国产| 成人a毛片久久免费播放| 久久国产精品久久国产精品| 国内精品久久九九国产精品| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 亚洲国产天堂久久综合网站|