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
相关文档:
一、字符串初始化方式
//第一种:大小确定的情况
char string1[10] = "I am a boy";
//第二种:自动计算大小
char string2[] = "I am a boy";
//第三种:初始化一个指针
char *string3 = "I am a boy";
//第四种:初始化一个指针数组
char *string4[10] = "I am a boy";
......
1.fopen()
fopen的原型是:FILE *fopen(const char
*filename,const char
*mode),fopen实现三个功能:为使用而打开一个流,把一个文件和此流相连接,给此流返回一个FILR指针。
参数filename指向要打开的文件名,mode表示打开状态的字符串,其
取值如下:
字符串 含义
"r" 以只读方式打开 ......
/*
* 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 ......