摘要:(转载,绝对的有用)lib被我们正确调用确总是无法解析。这是C++编译和C编译的区别时常在cpp的代码之中看到这样的代码: #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif 这样的代码到底是什么意思呢?首先,__cplusplus是cpp中的自定义宏,那么定义了这个宏的话表示这是一段cpp的代码,也就是说,上面的代码的含义是:如果这是一段cpp的代码,那么加入extern "C"{和}处理其中的代码。 要明白为何使用extern "C", 阅读全文
(转)探索C++的秘密之详解extern "C",这就是为什么很多.lib被我们正确调用确总是无法解析的。
2014-01-18 21:24 by hongjiumu, 499 阅读, 0 推荐, 收藏,用windowsapi来建立一个窗口
2014-01-18 21:22 by hongjiumu, 6191 阅读, 0 推荐, 收藏,
摘要:#include #include HINSTANCE g_hInstace = 0; LRESULT CALLBACK WindowProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { switch(nMsg) { case WM_QUIT: PostQuitMessage(0); ... 阅读全文
LPCTSTR
2014-01-18 21:21 by hongjiumu, 316 阅读, 0 推荐, 收藏,
摘要:#include #include int main() { LPCTSTR lpCChar; LPSTR lpStr="Hello"; int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, NULL, 0); wchar_t* decodedStr = new wchar_t[sizeNeeded ]; MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, decodedStr, sizeNeeded ); lpCChar=decod... 阅读全文
UTF8
2014-01-18 21:19 by hongjiumu, 198 阅读, 0 推荐, 收藏,
摘要:Here's a couple of functions (based on Brian Bondy's example) that use WideCharToMultiByte and MultiByteToWideChar to convert between std::wstring and std::string using utf8 to not lose any data.// Convert a wide Unicode string to an UTF8 string std::string utf8_encode(const std::wstring &am 阅读全文
friend ---- public and private
2014-01-18 21:13 by hongjiumu, 295 阅读, 0 推荐, 收藏,
摘要:I mean the difference between:class A{public: friend class B;};andclass A{private: //or nothing as the default is privatefriend class B;};Is there a difference?No, there's no difference - you just tell that class B is a friend of class A and now can access its private and protected members, that 阅读全文
c++中const使用详解
2014-01-18 21:12 by hongjiumu, 465 阅读, 0 推荐, 收藏,
摘要:const在c++中是一个关键字,它限定一个变量不允许被改变。使用const在一定程度上可以提高程序的安全性和可靠性,另外,在观看别人代码的时候,清晰理解const所起的作用,对理解对方的程序也有一些帮助。和const相反的是mutable,mutable也是一个关键字,它的作用刚好和const相反,是说明这个变量可以被改变,即使是在被const限定的类的成员函数里面。一:const和一般的变量相结合。int const a = 10,与 const int a =10 这两种写法都是正确的,也是表达同一个意思。说明变量a不能不修改,这种用法大家都知道,所以不用多说。需要说明的是:const 阅读全文
In c++ access control works on per-class basis not on per-object basis.
2014-01-01 18:21 by hongjiumu, 257 阅读, 0 推荐, 收藏,
摘要:#ifndef MYTIME_H #define MYTIME_H class MyTime { private: int m_hour; int m_minute; public: MyTime(int hour,int minute=0); ~MyTime(); MyTime operator+(const MyTime & time) const; void Show(); //int GetHour() const; //int GetMinute() const; }; #endif #include "... 阅读全文
realloc 用法
2013-12-30 19:58 by hongjiumu, 552 阅读, 0 推荐, 收藏,
摘要:#include #include #include int main() { char * p_char; //you should include - because that is where malloc() is declared p_char=(char *)malloc(100); int count(123456); count=count0) //{ // p_char=(char *)malloc(100); // count--; //} //#includ... 阅读全文
enum don't allocate any memory
2013-12-30 19:57 by hongjiumu, 228 阅读, 0 推荐, 收藏,
摘要:int main() { _asm{ mov edi,edi mov edi,edi } enum Color{Red=12,Green,Yellow}; _asm{ mov edi,edi mov edi,edi } Color c=Red; //The only valid values that you can assign to an enumeration variable without a type //cast are the enumerator values used in defining the type.... 阅读全文
(转)C++ STL中的vector的内存分配与释放
2013-12-22 11:13 by hongjiumu, 2739 阅读, 0 推荐, 收藏,
摘要:C++ STL中的vector的内存分配与释放http://www.cnblogs.com/biyeymyhjob/archive/2012/09/12/2674004.html1.vector的内存增长vector其中一个特点:内存空间只会增长,不会减小,援引C++ Primer:为了支持快速的随机访问,vector容器的元素以连续方式存放,每一个元素都紧挨着前一个元素存储。设想一下,当vector添加一个元素时,为了满足连续存放这个特性,都需要重新分配空间、拷贝元素、撤销旧空间,这样性能难以接受。因此STL实现者在对vector进行内存分配时,其实际分配的容量要比当前所需的空间多一些。就是 阅读全文
浙公网安备 33010602011771号