C/C++/VC MFC char & int study
测试代码一(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, *PT
相关文档:
50个c/c++源代码网站
文章出处:http://blog.chinaunix.net/u3/106835/showart_2190632.html
C/C++是最主要的编程语言。这里列出了50名优秀网站和网页清单,这些网站提供c/c++源代码
。这份清单提供了源代码的链接以及它们的小说明。我已尽力包括最佳的C/C++源代码的网站。这不是一个完整的清单,您有建议可以联系我, ......
#include <iostream>
using namespace std;
class Base {
public:
virtual void fn(int x) {
cout << "In Base class, int x = " << x << endl;
}
};
class SubClass : public Base {
public:
// 函数的重载,这样的重载方式,在Java中能行,在C/C++中却不行
virt ......
/*
* test.cpp
*
* Created on: 2010-5-13
* Author: Sarah
*/
#include "/usr/include/mysql/mysql.h" /*为绝对路径*/
#include <stdio.h>
#include <stdlib.h>
#i ......
使用NDK开发C/C++项目规则
<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;}@font-face {font-family:"\@宋体&qu ......