VC++中怎样把int,float转换为CString类型,再怎样转回,谢谢谢谢了!!!
刚开始学VC,请大家多帮助!!!
谢谢了!!!
7 个解决方案
#1
用函数atoi和atof~~~
#2
具体的例子:
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );
s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );
s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}
#3
假如有个CString类型strPrimeP,转化为整形
iPrimeP = atoi(strPrimeP.GetBuffer(strPrimeP.GetLength()));//CString转化为int
将int类型EncryValues转化为CString类型EncryMessage
EncryMessage.Format(_T("%d"), EncryValues);
~~~
iPrimeP = atoi(strPrimeP.GetBuffer(strPrimeP.GetLength()));//CString转化为int
将int类型EncryValues转化为CString类型EncryMessage
EncryMessage.Format(_T("%d"), EncryValues);
~~~
#4
楼上的兄弟好啊,怎样把int,float转换为CString类型的数据,谢谢!!!
#5
float fData;
int nData;
CString strFloat; strFloat.Format(_T("%f"), fData);
CString strInt; strInt.Format(_T("%d"), nData);
int nData;
CString strFloat; strFloat.Format(_T("%f"), fData);
CString strInt; strInt.Format(_T("%d"), nData);
#6
EncryMessage.Format(_T("%d"), EncryValues);
晕,不是已经写给你了~~
浮点型你自己改一下%d为%f不就可以了~~~
晕,不是已经写给你了~~
浮点型你自己改一下%d为%f不就可以了~~~
#7
谢谢各位兄弟位,问题解决了,呵呵!!!
#1
用函数atoi和atof~~~
#2
具体的例子:
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );
s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );
s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}
#3
假如有个CString类型strPrimeP,转化为整形
iPrimeP = atoi(strPrimeP.GetBuffer(strPrimeP.GetLength()));//CString转化为int
将int类型EncryValues转化为CString类型EncryMessage
EncryMessage.Format(_T("%d"), EncryValues);
~~~
iPrimeP = atoi(strPrimeP.GetBuffer(strPrimeP.GetLength()));//CString转化为int
将int类型EncryValues转化为CString类型EncryMessage
EncryMessage.Format(_T("%d"), EncryValues);
~~~
#4
楼上的兄弟好啊,怎样把int,float转换为CString类型的数据,谢谢!!!
#5
float fData;
int nData;
CString strFloat; strFloat.Format(_T("%f"), fData);
CString strInt; strInt.Format(_T("%d"), nData);
int nData;
CString strFloat; strFloat.Format(_T("%f"), fData);
CString strInt; strInt.Format(_T("%d"), nData);
#6
EncryMessage.Format(_T("%d"), EncryValues);
晕,不是已经写给你了~~
浮点型你自己改一下%d为%f不就可以了~~~
晕,不是已经写给你了~~
浮点型你自己改一下%d为%f不就可以了~~~
#7
谢谢各位兄弟位,问题解决了,呵呵!!!