Console应用程序
/subsystem:console /entry:mainCRTStartup (ANSI版)
/subsystem:console /entry:wmainCRTStartup (UNICODE版)
Windows应用程序:
/subsystem:windows /entry:WinMain (ANSI版)
/subsystem:windows /etnry:wWinMain (UNICODE版)
L是vc中的宏,将ANSI字符串转换成unicode的字符串。
strlen("asd") = 3;
strlen(L"asd") = 6;
(A/W/T)
_T是一个宏转换 ,让字符串在unicode和ansi两种编码形式下都编译没问题
PS:用 @ 引起来的优点在于换码序列“不”被处理,这样就可以轻松写出字符串,例如一个完全限定的文件名:
@"c:/Docs/Source/a.txt" //rather than "c://Docs//Source//a.txt"
编译Qt时,除了要做相应的上述类似设置之外,如果用到qt的一些宏的话,还需要进行预处理。qt的qmake会干这件事情。
有两种方法。
1在工程build options弹出对话框中的pre/post build steps标签中的pre-build steps编辑框中填上两行:
qmake -project
qmake ${projectname}.pro
这样即可编译,否则会报很多错误。
2 把Windows环境变量中include和lib中和VC编译器相关的路径都干掉,否则在qmake最终编译产生的文件中会包含一些产生类型识别问题的VC头文件。干掉之后,生成的Makefile.Debug或者Makefile.Release就是非常清爽正宗的makefile了。
3 在Compiler and debugger Settings中的Toolchain executables中选择gcc,g++,mingw32-make等。
4 在工程的Properties属性弹出对话框中,打勾check box:this is a custom Makefile。
5 注意,建工程之时,把输出文件目录bin或者obj都干掉,直接用Debug或Release作为输出目录。
6 清理。build options...对话框Make Commands标签中一个关于clean的编辑框中的clean$target换成$target-clean。
为了避免和其他头文件冲突, STL的头文件不再使用常规的.h扩展。为了包含标准的string类,迭代器和算法,用下面的指示符:
#include <string> #include <iterator> #include <algorithm>
如果你查看STL的头文件,你可以看到象iterator.h和stl_iterator.h这样的头文件。由于这些名字在各种STL实现之间都可能不同,你应该避免使用这些名字来引用这些头文件。为了确保可移植性,使用相应的没有.h后缀的文件名
char* s = new char[100];
delete[] s; // delete s;
严格的说,上述代码是不正确的,因为我们在分配内存时使用的是new[],而并不是简单的new,但释放内存时却用的是delete。正确的写法是使用delete[]:
class MyClass
{
int a;
public:
MyClass() { printf("ctorn"); }
~MyClass() { printf("dtorn"); }
};
void* operator new[](size_t size)
{
void* p = operator new(size);
printf("calling new[] with size=%d address=%pn", size, p);
return p;
}
void * operator delete[] (){
........
}
// 主函数
MyClass* mc = new MyClass[3];
printf("address of mc=%pn", mc);
delete[] mc;
运行此段代码,得到的结果为:(VC2005)
calling new[] with size=16 address=003A5A58
ctor ctor ctor
address of mc=003A5A5C
dtor dtor dtor
template <class T> T* New[](int count)
template <class T> void Delete[](T* pt)
new operator、operator new、placement new
Unicode环境下是wchar_t ,ANSI下是char
Unicode下,一个字符代表两个字节, Ansi下是一个字符
sprintf函数的功能与printf函数的功能基本一样,只是它把结果输出到指定的字符串中了
#define DWORD unsigned long
表示一个32位无符号整型数,或用来表示段地址和段地址的偏移量; #include<windows.h>
GC.GetTotalMemory(false)
GC.CollectionCount(0)
REF驱动,它用软件的方式虚拟这些功能.比如我们要测试顶点和像素阴影,但我们的显卡不支持,那么我们就可能通过REF驱动的方式来测试我们的代码,不过这种方式只能用来测试我们的代码,不要把他们发布给我们的最终用户,因为这种方式只存在于SDK中,并且奇慢无比