CString轉換為double 創 轉

2021-05-24 22:20:46 字數 1033 閱讀 7158

cstring轉換為double:

cstring strfloat;

float flt;或double fit

不過前面兩種方法在vs2005下執行結果不正確,在vc6.0開發環境下是可以的。

【說明:網上很多說的都是前兩種方法,結果double值只是字串的第乙個數字。】

//方法一

flt = (float)atof((char *)(lptstr)(lpctstr)mstrfloat);

或flt = (float)atof((lpstr)mstrfloat);

//方法二

flt = (float)atof((char *)m_eps.getbuffer(strfloat.getlength()));

strfloat.releasebuffer();

//方法三

//convert cstring to double

static bool _atl******floatparse(lpctstr lpsztext, double& d)  

tchar chfirst = lpsztext[0];  

d = _tcstod(lpsztext,(lptstr*)&lpsztext);  

if (d == 0.0 && chfirst != '0')

while (*lpsztext == ' '|| *lpsztext == '/t')

if (*lpsztext != '/0')

return true;  

}另外,也可以這樣:

const char* a;

a="123.5";

double b=atof(a);

//b==123.500000000000000

double轉換為cstring:

例子:cstring a;

double b=123.5;

a.format("%f",b);//int用%d,dword用%u,double,float用%f

//a=="123.5"

vc下cstring轉換為float

2009 07 08 09 57 22 分類 vc型別轉換 字型大小 訂閱 cstring str cstring almost mad float tempfloat 0.0 tempfloat atof str 但是出現這樣的錯誤 error c2664 atof cannot convert ...

Mfc下CString轉換為char

下面分享一下新心得 mfc 下cstring 轉char uses conversion char name w2a m name.getbuffer m name.getlength 1 char code w2a m code.getbuffer m code.getlength 1 windo...

c string型別轉換為char 型別

string 是c 標準庫裡面其中乙個,封裝了對字串的操作 把string轉換為char 有3中方法 1。data 如 string str abc char p str.data 2.c str 如 string str gdfd char p str.c str 3 copy 比如 string...