想把float转成char *,应为不知道有没有直接转化的函数,就自己定义了一个函数char *f_c(float f)
{
CString c1; c1.Format("%f", f);
char *c = (LPSTR)(LPCTSTR)c1;
return c;
}
void main()
{ float f = 10;
char *tem = f_c(f);
}值却没有返回来,不知道原因,看样子是个小问题,可就是找不到毛病!
在函数调用阶段只是正确的,而且也成功转换了,就是没有传回来。
{
CString c1; c1.Format("%f", f);
char *c = (LPSTR)(LPCTSTR)c1;
return c;
}
void main()
{ float f = 10;
char *tem = f_c(f);
}值却没有返回来,不知道原因,看样子是个小问题,可就是找不到毛病!
在函数调用阶段只是正确的,而且也成功转换了,就是没有传回来。
abs Find absolute value of integer
atof Convert string to float
atoi, _atoi64 Convert string to int
atol Convert string to long
_ecvt Convert double to string of specified length
_fcvt Convert double to string with specified number of digits following decimal point
_gcvt Convert double number to string; store string in buffer
_itoa, _i64toa, _itow, _i64tow Convert int to string
labs Find absolute value of long integer
_ltoa, _ltow Convert long to string
_mbbtombc Convert 1-byte multibyte character to corresponding 2-byte multibyte character
_mbcjistojms Convert Japan Industry Standard (JIS) character to Japan Microsoft (JMS) character
_mbcjmstojis Convert JMS character to JIS character
_mbctohira Convert multibyte character to 1-byte hiragana code
_mbctokata Convert multibyte character to 1-byte katakana code
_mbctombb Convert 2-byte multibyte character to corresponding 1-byte multibyte character
mbstowcs Convert sequence of multibyte characters to corresponding sequence of wide characters
mbtowc Convert multibyte character to corresponding wide character
strtod, wcstod Convert string to double
strtol, wcstol Convert string to long integer
strtoul, wcstoul Convert string to unsigned long integer
strxfrm, wcsxfrm Transform string into collated form based on locale-specific information
__toascii Convert character to ASCII code
tolower, towlower, _mbctolower Test character and convert to lowercase if currently uppercase
_tolower Convert character to lowercase unconditionally
toupper, towupper, _mbctoupper Test character and convert to uppercase if currently lowercase
_toupper Convert character to uppercase unconditionally
_ultoa, _ultow Convert unsigned long to string
wcstombs Convert sequence of wide characters to corresponding sequence of multibyte characters
wctomb Convert wide character to corresponding multibyte character
_wtof Convert wide-character string to a double
_wtoi, _wtoi64 Convert wide-character string to int or __int64
_wtol Convert wide-character string to long
用fcvt可以完成转换,这是MSDN中的例子:
int decimal, sign;
char *buffer;
double source = 3.1415926535;
buffer = _fcvt( source, 7, &decimal, &sign );
运行结果:source: 3.1415926535 buffer: '31415927' decimal: 1 sign: 0
decimal表示小数点的位置,sign表示符号:0为正数,1为负数
{ c1.Format("%f", f);
return cl;
}
这样改你看看