C/C++/VC MFC----char & int---study
2010-05-14 22:23
561 查看
测试代码一(VC6.0、C-code):
#include <stdio.h>
void main()
{
int aa;
unsigned char j1,j2;
aa=j1=j2=0;
aa=49;
j1=aa;
printf("j1=%d /n",j1);
j2=aa;
printf("j2=%c /n",j2);
}
【分析】:
[1]正如所想象的输出结果:
j1=49
j2=1
Press any key to continue
[2]先说明aa在内存中的存储形式:0x0031;
[3]j1 ,j2同为unsigned char型数据;
[4]上述二变量输出结果不一致;由prinf()函数中的格式符不同所致;
[5]这里认为:其一,对于 %d格式符,pintf()能“正确”反映 j1 中存储的数据;
其二,对于 %c格式符,printf() 却不能“正确”反映 j2(==aa)中存储的二进制数据。
[6]对于以上分析的理解:显然,printf()函数将会依照用户提供给它的 格式符 对待输出的数据进行
“处理”后,输出至显示设备上。
[7]……
测试代码二(VC6.0 ,VC mfc):
int aa,bb;
aa=bb=0;
CString strtemp,display;
strtemp.Format("%c",170); //170==0xAA
MessageBox(strtemp);
int length=strtemp.GetLength();
for(int i=0;i<length;i++)
{
aa+=strtemp.GetAt(i);
bb+=(unsigned char)strtemp.GetAt(i);
}
display.Format("(TCHAR)aa=%x",aa);
MessageBox(display);
display.Format("(unsigned char)bb=%x",bb);
MessageBox(display);
【分析】:
[1]输出清单如下:
MessageBox(strtemp);===== "?"
display.Format("(TCHAR)aa=%x",aa);
MessageBox(display);====="(TCHAR)aa=ffffffaa" //(ff ff ff aa)
display.Format("(unsigned char)bb=%x",bb);
MessageBox(display);====="("(unsigned char)bb=aa"
[2] // return single character at zero-based index
TCHAR GetAt(int nIndex) const;
<来源:CString-class;最终解释为microsoft VC6.0>
[3]typedef char TCHAR, *PTCHAR;
<来源:WINNT.H;最终解释为microsoft VC6.0>
关于typedef 说明如下:
typedef int COUNT;
COUNT i, j ;
<C程序设计/谭浩强 著. ——3版. ——北京:清华大学出版社,2005.7,引文来自:P316>
[4]……
[5]……
#include <stdio.h>
void main()
{
int aa;
unsigned char j1,j2;
aa=j1=j2=0;
aa=49;
j1=aa;
printf("j1=%d /n",j1);
j2=aa;
printf("j2=%c /n",j2);
}
【分析】:
[1]正如所想象的输出结果:
j1=49
j2=1
Press any key to continue
[2]先说明aa在内存中的存储形式:0x0031;
[3]j1 ,j2同为unsigned char型数据;
[4]上述二变量输出结果不一致;由prinf()函数中的格式符不同所致;
[5]这里认为:其一,对于 %d格式符,pintf()能“正确”反映 j1 中存储的数据;
其二,对于 %c格式符,printf() 却不能“正确”反映 j2(==aa)中存储的二进制数据。
[6]对于以上分析的理解:显然,printf()函数将会依照用户提供给它的 格式符 对待输出的数据进行
“处理”后,输出至显示设备上。
[7]……
测试代码二(VC6.0 ,VC mfc):
int aa,bb;
aa=bb=0;
CString strtemp,display;
strtemp.Format("%c",170); //170==0xAA
MessageBox(strtemp);
int length=strtemp.GetLength();
for(int i=0;i<length;i++)
{
aa+=strtemp.GetAt(i);
bb+=(unsigned char)strtemp.GetAt(i);
}
display.Format("(TCHAR)aa=%x",aa);
MessageBox(display);
display.Format("(unsigned char)bb=%x",bb);
MessageBox(display);
【分析】:
[1]输出清单如下:
MessageBox(strtemp);===== "?"
display.Format("(TCHAR)aa=%x",aa);
MessageBox(display);====="(TCHAR)aa=ffffffaa" //(ff ff ff aa)
display.Format("(unsigned char)bb=%x",bb);
MessageBox(display);====="("(unsigned char)bb=aa"
[2] // return single character at zero-based index
TCHAR GetAt(int nIndex) const;
<来源:CString-class;最终解释为microsoft VC6.0>
[3]typedef char TCHAR, *PTCHAR;
<来源:WINNT.H;最终解释为microsoft VC6.0>
关于typedef 说明如下:
typedef int COUNT;
COUNT i, j ;
<C程序设计/谭浩强 著. ——3版. ——北京:清华大学出版社,2005.7,引文来自:P316>
[4]……
[5]……
相关文章推荐
- [C++ VC MFC] char* str="heelo"与char str[]="heelo"区别
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- 【转】[VC/C++]CString,int,string,char*之间的转换2007-11-06 23:26string 转 CString
- 转载:[VC/C++]CString,int,string,char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*转换(转)
- MFC/C++/C中CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- [VC/C++]CString,int,string,char*之间的转换
- c++ MFC int 转换成 CString
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- [VC/C++]CString,int,string,char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换
- MFC/C++/C中字符类型CString, int, string, char*之间的转换