線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1262
推到 Plurk!
推到 Facebook!

Converting a number to/from an Hex / String

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-17 13:12:19 IP:61.218.xxx.xxx 未訂閱

Converting a number to/from an hex/string

資料來源:http://www.leunen.com/cbuilder/tips.html These little functions convert a number to an hex or to a string and vice versa. #include < sstream > #include < string > #include < exception > //--------------------------------------------------------------------------- // Convert a number to a string
template
std::string ToStr(const T &value)
{
  std::ostringstream oss;
  if(!(oss<
//---------------------------------------------------------------------------
// Convert a string to a number
template
T ToInt(const std::string &str)
{
  if(str.size()==0)return 0;
  std::istringstream iss(str);
  T result=0;
  if(!(iss>>std::dec>>result))throw exception("Invalid argument");
  return result;
}    
//--------------------------------------------------------------------------- // Convert an hex string to a number
template
T HexToInt(const std::string &str)
{
  if(str.size()==0)return 0;
  std::istringstream iss(str);
  T result=0;
  if(!(iss>>std::hex>>result))throw exception("Invalid argument");
  return result;
}
//--------------------------------------------------------------------------- // Convert a number to an hex string
template
std::string ToHex(const T &value)
{
  std::ostringstream oss;
  if(!(oss<        發表人 - axsoft 於 2003/03/17  13:16:46
        
系統時間:2024-04-25 21:04:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!