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

             

            [導(dǎo)入]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)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久国产成人精品亚洲午夜| 欧美亚洲国产精品久久| 精品国际久久久久999波多野| 久久精品国产久精国产思思| 久久99热狠狠色精品一区| 久久精品国产精品亜洲毛片| 国产成人精品综合久久久| 91久久精一区二区三区大全| 久久综合一区二区无码| 久久精品人人槡人妻人人玩AV | 伊人久久亚洲综合影院| 婷婷综合久久中文字幕蜜桃三电影 | 国产精品99久久精品| 久久久久亚洲精品男人的天堂 | 久久久久亚洲精品无码蜜桃| 久久久久18| 狠狠色丁香婷婷综合久久来| 久久婷婷五月综合色奶水99啪| 日本道色综合久久影院| 人妻精品久久久久中文字幕一冢本| 久久国产综合精品五月天| AV无码久久久久不卡网站下载| 亚洲国产综合久久天堂| 精品水蜜桃久久久久久久| 国产99久久精品一区二区| 亚洲人成伊人成综合网久久久 | 久久av无码专区亚洲av桃花岛| 亚洲国产成人乱码精品女人久久久不卡 | 亚洲日本久久久午夜精品| 国产激情久久久久影院老熟女免费| 精品乱码久久久久久久| 色综合久久久久久久久五月| 丁香色欲久久久久久综合网| 午夜视频久久久久一区 | 久久成人国产精品| 亚洲AV无码1区2区久久| 一本色道久久88精品综合| 区久久AAA片69亚洲| 久久精品国产亚洲AV不卡| 久久99精品久久久大学生| 久久亚洲熟女cc98cm|