• <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 閱讀(377) 評論(0)  編輯 收藏 引用

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            91精品国产高清久久久久久国产嫩草| 天堂无码久久综合东京热| 久久精品无码专区免费东京热| 亚洲AV日韩AV天堂久久| 久久91精品国产91久久小草| 久久99精品久久久久久齐齐| 久久伊人五月丁香狠狠色| 粉嫩小泬无遮挡久久久久久| 人人狠狠综合久久亚洲高清| 激情伊人五月天久久综合| 亚洲精品高清一二区久久| 成人久久精品一区二区三区| 国产精品久久久久a影院| 久久亚洲欧美日本精品| 一本一道久久综合狠狠老| 久久99亚洲综合精品首页| 久久精品夜夜夜夜夜久久| 久久精品国产99久久久古代| 亚洲国产天堂久久综合网站 | 性做久久久久久久久久久| 久久久久女人精品毛片| 国产69精品久久久久观看软件| 久久国产精品久久精品国产| 久久久一本精品99久久精品66| 伊人热热久久原色播放www | 国产精品成人久久久久三级午夜电影 | 性欧美丰满熟妇XXXX性久久久 | 午夜精品久久久久久久| 国产女人aaa级久久久级| 国产精品久久亚洲不卡动漫| 久久精品成人欧美大片| 性欧美大战久久久久久久| 久久久久九国产精品| 久久e热在这里只有国产中文精品99| 69SEX久久精品国产麻豆| 久久99精品国产麻豆| 久久精品国产只有精品2020| 91秦先生久久久久久久| 精品久久久无码中文字幕| 久久久久免费视频| 亚洲国产精品一区二区三区久久|