随笔分类 - c++
C++
摘要:// signUnsignCompare.cpp : Defines the entry point for the console application. // #include "stdafx.h" int main(int argc, char* argv[]) { int i=-5; unsigned int j=0; if (i>j) { ...
阅读全文
摘要:// refPoint.cpp : Defines the entry point for the console application. // #include "stdafx.h" int main(int argc, char* argv[]) { int i=2,j=3; int *p=&i; int &r=*p; printf("%d\n",r);...
阅读全文
摘要:// mapTest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include using namespace std; int main(int argc, char* argv[]) { map test; ...
阅读全文
摘要:#include #include using namespace std; void main_1() { vector vecIntA;//默认构造函数 vector vecIntB(vecIntA);//调用拷贝构造函数 int iSize=vecIntA.size();//放回容器中元素的个数 bool isEmpty=vecIntA.e...
阅读全文
摘要:void IntToBinaryString(int devisor,char* pBinStr) { int i; int remainder; for(i=0;i> 1; pBinStr[i]=(remainder == 1)?'1':'0'; } pBinStr[8]='\0'; } void mai...
阅读全文
摘要:#include #include #include using namespace std; struct SelfType{ int number; }; void map_find() { //map.lower_bound(keyElem);//返回第一个key>=keyElem元素的迭代器 //map.upper_bound(keyElem);//返回第一...
阅读全文
摘要:#include using namespace std; template class MyClass{ public: template MyClass(const MyClass& x) { cout& x)"& x) { cout& x)" xd; cou...
阅读全文
摘要:#include using namespace std; template class MyClass{ private: T value; public: void assign(const MyClass & obj) { this->value=obj.value; } MyClass(T value) ...
阅读全文
摘要:#include using namespace std; template class MyClass{ public: typename T::SubType * ptr;//vc6里面,此处“typename”可有可无,vs2010里面,此处“typename”必须有 }; class Test{ public: typedef int SubType; }; v...
阅读全文
摘要:#include using namespace std; template class Test{ public: T1 NumNBei(T1 num,T2 N) { return num*N; } }; void main() { Test t; double x= t.NumNBei(2.3,2); cout<<x<<end...
阅读全文
摘要:#include int main() { #if _PLATFORM_ == _PLATFORM_TRU64 printf("Hello _PLATFORM_TRU64!\n"); #endif #if _PLATFORM_ == _PLATFORM_WIN32 printf("Hello _PLATFORM_WIN32!\n"); #endif return 0...
阅读全文
摘要:#include #include #include using namespace std; class Student { public: Student(int age,string name) { m_age=age; m_name=name; } Student(const Student &stu) { ...
阅读全文
摘要:#include #include using namespace std; void changeFirst(char* c) { c[0]+=1; } int main(int argc, char ** argv_) { int i = 100; int *j = &i; const int *k = const_cast(j); //co...
阅读全文
摘要:#include #include //front push pop back push pop [] at() #include #include #include //remove using namespace std; void listTest() { int iArray[]={1,2,3,4,5,3,3,3,3,3,6}; list listInt(i...
阅读全文
摘要:#include #include using namespace std; void Test(); void main() { int a[]={1,2,3,4,5}; vector v_a(a,a+5); vector v_b(v_a.begin(),v_a.end()); vector::iterator it; for (it=v_...
阅读全文
摘要:#include #include using namespace std; void main() { vector vInt; vInt.push_back(1); vInt.push_back(2); vInt.push_back(3); vInt.push_back(4); vInt.push_back(5); vector::...
阅读全文
摘要:// TemplateFunction.cpp : Defines the entry point for the console application. // #include "stdafx.h" template T MyMax(T a,T b) { return a>b ? a : b; } int main(int argc, char* argv[]) { i...
阅读全文
摘要:#include #include using namespace std; void main() { string s="Hello Lucy!"; //s.replace(5,1,"Lily"); //"Lucy" -> "Lily" int indexStart=s.find("Lucy"); string l("Lily"); in...
阅读全文