小技巧

来源:互联网 发布:新浪通达信炒股软件 编辑:程序博客网 时间:2024/05/16 06:23


带符号整形四舍五入

tScore =static_cast<int>(tScore/10.0 +((tScore>>(sizeof(tScore)*8 - 1))) + 0.5) *10;


类初始化

1.没有虚函数
memset(this ,0,sizeof(ClassName));
2.有虚函数(不知道对不对)
int a =(int)((this));

memset((void *)(a + 4) ,0,sizeof(ClassName));


字符大小写互换

str[i] = str[i] ^ 0x20;

#include <iso646.h>

可以使用宏  or and not 等等


#ifdef  _WIN64
#define offsetof(s,m)   (size_t)( (ptrdiff_t)&reinterpret_cast<const volatile char&>((((s *)0)->m)) )
#else
#define offsetof(s,m)   (size_t)&reinterpret_cast<const volatile char&>((((s *)0)->m))
#endif


vs  输入提示   Ctrl+Alt+t

原创粉丝点击