![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++技术
梦之安魂曲
喜欢C++,喜欢PHP,做过桌面软件,如今做WEB开发。
展开
-
大小写转换函数,位运算的使用
#include#include#include#includeusing namespace std;void ToUpper(char *str){ char *beg=str; char ch; for(int i=0,length=strlen(str);i='a'&&ch='A'&&ch原创 2011-04-27 09:46:00 · 730 阅读 · 0 评论 -
MFC消息映射宏展开后代码
const AFX_MSGMAP* theClass::GetMessageMap() const { return GetThisMessageMap(); } const AFX_MSGMAP* PASCAL theClass::GetThisMessageMap() { typedef theClass ThisClass; typedef baseC原创 2012-02-26 22:26:26 · 654 阅读 · 0 评论 -
C++中实现C#属性相似的语法
#include#includeusing namespace std;templateResultFunction function_cast(Function fun){ ResultFunction result=ResultFunction(*(reinterpret_cast(&fun))); return result;}template//,ty原创 2012-02-17 00:38:33 · 783 阅读 · 0 评论 -
C++指向类成员函数的指针
最近在开发中用到了函数指针,于是想整理了一下有关函数指针的概念。O(∩_∩)O~首先 函数指针是指向一组同类型的函数的指针;而类成员函数我们也可以相似的认为,它是指向同类中同一组类型的成员函数的指针,当然这里的成员函数更准确的讲应该是指非静态的成员函数。前者是直接指向函数地址的,而后者我们从字面上也可以知道 它肯定是跟类和对象有着关系的。函数指针实例:typedef int (*p)(转载 2012-02-17 16:49:17 · 407 阅读 · 0 评论 -
C++ builder 网络聊天程序
#include #pragma hdrstop#include "main.h"//---------------------------------------------------------------------------#pragma link "ScktComp"#pragma resource "*.dfm"TChatForm *ChatForm;原创 2012-07-02 15:54:53 · 1598 阅读 · 0 评论 -
关于二维指针的代码
#include #include using namespace std;struct mst{ int *a; double f; int *b; int *c;};int main(){ mst st; int array1[2]={1,2}; int array2[3]={3,4,5};原创 2012-07-15 14:59:20 · 429 阅读 · 0 评论 -
大端模式和小端模式
大端格式:在这种格式中,字数据的高字节存储在低地址中,而字数据的低字节则存放在高地址中;小端格式:与大端存储格式相反,在小端存储格式中,低地址中存放的是字数据的低字节,高地址存放的是字数据的高字节。判断计算机系统是大端还是小端的代码:bool isBig_Endian(){ unsigned short test=0x1234; if(*((unsigned char*)原创 2012-04-19 19:00:45 · 953 阅读 · 0 评论 -
关于二级指针
#include #include #include using namespace std;struct mst{ int *a;//对齐,扩展为8字节 double f; int *b; int *c;};int main(){ mst st; int array1[2]= {1,2}; int array2[3]= {3,4,5}; int array3[2]原创 2012-07-16 13:47:56 · 541 阅读 · 0 评论 -
写着玩的代码
#include#include#includevoid output_empty(int n){ for(int i=0;i<n;i++) { printf(" "); }}int main(){ int i,j; for(int k=0;k<60;k++) { for(i=1;i<=5;i++) { output_empty(k); for(原创 2012-04-09 22:27:10 · 368 阅读 · 0 评论 -
浮点数整数部分和小数部分的分离
void PrintFloat(float value){ int FloatValue = *reinterpret_cast(&value); if(FloatValue&0x80000000) //最高位为符号位 cout<<"-"<<endl; int Exp = (FloatValue>>23)&0xff; //取得指数字段,一个字节。第二到第原创 2013-04-19 14:54:17 · 11814 阅读 · 1 评论 -
数组大小作为参数传递(通过模板数值参数)
#include#includeusing namespace std;templatevoid OutputArraySize(type (&ar)[size]){ cout<<"the array size is:"<<size<<endl;}int main(){ int ar[5]; double dous[10]; OutputArraySize(ar);原创 2012-02-14 13:54:29 · 868 阅读 · 0 评论 -
数值计算的符号转换和溢出
#include#includeusing namespace std;int main(){ unsigned short x=32; signed short y=-35; unsigned short z=x+y;//y根据singed short会被隐式转换为unsigned short,y会被转换成无符号数 cout<<z<<endl;//结果为65535+1-y+x。此原创 2012-02-10 12:37:50 · 851 阅读 · 0 评论 -
控制台颜色控制函数
SetConsoleTextAttribute(hOutput,Forg);是windows.h中的WINDOWS API函数。原创 2011-07-06 10:37:14 · 502 阅读 · 0 评论 -
MS C++的for each关键字
#include "stdafx.h"#include #include #include #include #include using namespace std;int _tmain(int argc, _TCHAR* argv[]){ std::原创 2011-07-20 08:19:01 · 682 阅读 · 0 评论 -
类的引用类型成员
#include using namespace std;class Object{ int &count; public: Object(int &cou):count(cou){}; //如果函数为Object(int cou)则count引用了形参。 ~Object(){}; void SetValue(int cou) { count=cou原创 2011-11-24 11:35:09 · 1757 阅读 · 0 评论 -
优化问题关于const第二篇
int main(){ const int maxint=100;//此段代码放到main函数外程序会运行时崩溃掉 int &msg=const_cast(maxint); msg*=200; print_value(maxint); cout<<"max:"<<maxint<<endl; return 0;}原创 2011-12-28 23:27:40 · 485 阅读 · 0 评论 -
C++中通过自定义operator new 实现内存分配跟踪
#include#includeusing namespace std;void* operator new(size_t size,const char *msg,int line){ cout<<"the file:"<<(char*)msg<<" line number:"<<line<<" and size is:"<<size<<endl; return mall原创 2012-01-22 20:31:33 · 1236 阅读 · 0 评论 -
auto_ptr预防作为STL容器元素的实现。
#include#include#include#includeusing namespace std;class Widget{ public: Widget(int _id):id(_id){} void SayHello() { cout<<"my id:"<<id<<endl; } ~原创 2012-01-21 00:03:36 · 397 阅读 · 0 评论 -
mem_fun和bind2nd的用法例子
#include#include#includeusing namespace std;class Widget:public unary_function{ int id; public: Widget(int x):id(x){} void Multiply(int x) const {原创 2012-01-28 22:42:48 · 792 阅读 · 0 评论 -
成员函数转换普通函数
#include#includeusing namespace std;class Widget{ string name;public: Widget(string _name):name(_name) { } ~Widget() { //cout<<"goodbye:"<<name<<endl; } void Show(string &str) { cout原创 2010-11-09 09:47:00 · 968 阅读 · 0 评论 -
拷贝构造函数
拷贝构造函数是C++最基础的概念之一,大家自认为对拷贝构造函数了解么?请大家先回答一下三个问题:1. 以下函数哪个是拷贝构造函数,为什么?X::X(const X&); X::X(X); X::X(X&, int a=1); X::X(X&, int a=1, b=2); 2. 一个类中可以存在多于一个的拷贝构造函数吗?3. 写出以下程序段的输出结果,转载 2012-02-08 22:41:46 · 348 阅读 · 0 评论 -
singleton的实现代码
#include #include #include using namespace std;templateclass Singleton{public: static T* Instance() { if(ObjectPtr.get()==NULL) ObjectPtr.reset(new T()); retu原创 2014-04-15 15:23:17 · 842 阅读 · 1 评论