1UpdateData ();
如果绑定了控件变量,那么这个操作会把控件中数据映射到绑定的数据中.
2转换到字符串类型
1.用sprintf()函数来实现,即按照某种规定好的格式将数据写到字符串中。该函数原型如下:
int sprintf(char *buffer, const char *format [,argument] …);
使用方法如下:
#include <stdio.h>
void main( void ){
char buffer[200], s[] = "computer", c = 'l';
int i = 35, j;
float fp = 1.7320534f;
/* Format and print various data: */
j = sprintf( buffer, " String: %s
", s );
j += sprintf( buffer + j, " Character: %c
", c );
j += sprintf( buffer + j, " Integer: %d
", i );
j += sprintf( buffer + j, " Real: %f
", fp );
printf( "Output:
%s
character count = %d
", buffer, j );
}
Output:
String: computer
Character: l
Integer: 35
Real: 1.732053
character count = 71
◆ 2.使用CString类提供的Format()函数,也可以将数据按照某种规定格式写入字符串:
CString str;
str.Format("%d",n);
这样也可以很简单地实现基本数据类型到字符串的转换。
◆ 3.用_itoa(),*_i64toa()系列函数,这是在程序中经常用到的小函数,其原型如下:
char *_itoa(int value,char *string,int radix );
char *_i64toa(__int64 value, char *string, int radix );
char * _ui64toa( unsigned _int64 value, char *string,int radix );
wchar_t * _itow(int value, wchar_t *string, int radix );
wchar_t * _i64tow( __int64 value, wchar_t *string, int radix );
wchar_t * _ui64tow(unsigned __int64 value, wchar_t *string, int radix);
使用方法如下:
void main( void ){
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL;
_itoa( i, buffer, 10 );
printf( "String of integer %d (radix 10): %s
", i, buffer );
_itoa( i, buffer, 16 );
printf( "String of integer %d (radix 16): 0x%s
", i, buffer );
_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s
", i, buffer );
_ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s
", l, buffer );
_ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s
", ul,buffer );
}
输出结果如下:
String of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2