随笔分类 -  c++ 再学习记录

嘿嘿ie,i am coming
stl 的utility
摘要:std::pair#include <iostream>#include <utility>#include <string>using namespace std;int main () { pair <string,double> product1 ("tomatoes",3.25); pair <string,double> product2; pair <string,double> product3; product2.first = "lightbulbs"; // ty 阅读全文

posted @ 2012-12-30 14:41 GIS-MAN 阅读(454) 评论(0) 推荐(0)

迭代器
摘要:迭代器是内部做好的模板 可以用在迭代器的操作有 *, ++, ==, !=, list<char> testchar; list<char>::iterator pos; for(pos=testchar.begin();pos!=testchar。end();++pos) // 一般用++pos ,不是pos++ ,这样更快 { cout<< *pos; // *pos 代表当前元... 阅读全文

posted @ 2012-12-30 10:58 GIS-MAN 阅读(254) 评论(0) 推荐(0)

c++标准库的构成
摘要:http://en.wikipedia.org/wiki/C%2B%2B看看wiki 的解释:The language began as enhancements to C, first adding classes, then virtual functions, operator overloading, multiple inheritance,templates, and exception handling among other features. After years of development, the C++ programming language standard w 阅读全文

posted @ 2012-12-06 15:57 GIS-MAN 阅读(596) 评论(0) 推荐(1)

c++ 重载的操作符
摘要:可重载的 输出操作符<< 的重载 为了与 IO 标准库一致,操作符应接受 ostream& 作为第一个形参,对类类型 const 对象的引用作为第二个形参,并返回对ostream 形参的引用。 重载输出操作符一般的简单定义如下: // general skeleton of the overloaded output operator ostream& operator ... 阅读全文

posted @ 2012-12-06 15:01 GIS-MAN 阅读(323) 评论(0) 推荐(0)

win32 保存数据到剪切板
摘要:char cD[] ="http://rfb."; if(OpenClipboard(NULL)) { HGLOBAL hmem=GlobalAlloc(GHND,20); char *pmem=(char*)GlobalLock(hmem); EmptyClipboard(); memcpy(pmem,cD,20); SetClipboardData(CF_TEXT,hmem); CloseClipboard(); GlobalFree(hmem); }wchar 转成charconst WCHAR* guidchar test[6]... 阅读全文

posted @ 2012-11-27 17:25 GIS-MAN 阅读(262) 评论(0) 推荐(0)

c++ function template
摘要:以swapValues 为例 有时候不止想比较int ,还想比较char 类型的自定义类型的,为了代码重用和灵活性, 可使用void swapValues( int& variable1, int& variable2) {int temp; temp = variable1; variable1 = variable2; variable2 = temp; }语法template<class T>// 也可以有两个参数template<class T1, class T2>void swapValues(T& variable1, T& 阅读全文

posted @ 2012-11-13 10:46 GIS-MAN 阅读(520) 评论(0) 推荐(0)

类里面没有参缺省构造函数 的带来的问题
摘要:对于很多对象来说,不利用外部数据进行完全的初始化是不合理的。比如一个没有输入姓名的地址簿对象,就没有任何意义class EquipmentPiece { public: EquipmentPiece(int IDNumber); ... };因为 EquipmentPiece 类没有一个缺省构造函数,所以在三种情况下使用它,就会遇到问题(1) 第一中情况是建立对象数组时 ——EquipmentPiece bestPieces[10]; // 错误!没有正确调用 EquipmentPiece 构造函数 EquipmentPiece *bestPiec... 阅读全文

posted @ 2012-11-13 10:27 GIS-MAN 阅读(830) 评论(0) 推荐(0)

new操作符(new operator) 和 new操作(operator new)的区别。
摘要:当你写这样的代码: string *ps = new string("Memory Management"); 你使用的 new 是 new 操作符。这个操作符就象 sizeof 一样是语言内置的,你不能改变它的含义,它的功能总是一样的。它要完成的功能分成两部分。第一部分是分配足够的内存以便容纳所需类型的对象。第二部分是它调用构造函数初始化内存中的对象。new操作符总是做这两件事情,你不能以任何方式改变它的行为。你所能改变的是如何为对象分配内存。new 操作符调用一个函数来完成必需的内存分配,你能够重写或重载这个函数来改变它的行为。new 操作符为分配内存所调用函数的名字是 阅读全文

posted @ 2012-11-13 10:11 GIS-MAN 阅读(2486) 评论(0) 推荐(0)

c++ 顺序容器
摘要:种顺序容器(sequential container)。它将单一类型元素聚集起来成为容器,然后根据位置来存储和访问这些元素,这就是顺序容器。顺序容器的元素排列次序与元素值无关,而是由元素添加到容器里的次序决定。vector、list 和 deque 容器内元素的类型约束• 元素类型必须支持赋值运算。 • 元素类型的对象必须可以复制。差别在于访问元素的方式,以及添加或删除元素相关操作的运行代价顺序容器适配器包括 stack、queue 和 priority_queue 类型#include <vector> #include <list> #include <deq 阅读全文

posted @ 2012-11-10 16:14 GIS-MAN 阅读(238) 评论(0) 推荐(0)

分享一个c++ 加密算法 ,在百度贴吧找的,比较好玩
摘要://benny-crypt#include <iostream>#include <cmath>void encrypt();void decrypt();void backdoor();int main() {using namespace std;cout<<"欢迎来到Benny测试加密程序\n";cout<<"在控制台窗口右击可选择编辑-标记、复制、粘贴\n";cout<<"请选择你想要进行的任务,加密(1),解密(2),0退出\n";cout<<" 阅读全文

posted @ 2012-11-09 15:13 GIS-MAN 阅读(423) 评论(0) 推荐(0)

c++类型转换
摘要:const_cast最普通的用途就是转换掉对象的 const 属性。class Widget { ... }; class SpecialWidget: public Widget { ... }; void update(SpecialWidget *psw); SpecialWidget sw; // sw 是一个非 const 对象。 const SpecialWidget& csw = sw; // csw 是 sw的一个引用 它是一个 const 对象 update(&csw); // 错误!不能传递一个 const SpecialWidget*... 阅读全文

posted @ 2012-10-31 10:32 GIS-MAN 阅读(169) 评论(0) 推荐(0)

指针与引用的区别
摘要:string& rs; // 错误,引用必须被初始化 string s("xyzzy"); string& rs = s; // 正确,rs指向 s 指针没有这样的限制。 string *ps; // 未初始化的指针 // 合法但危险指针与引用的另一个重要的不同是指针可以被重新赋值以指向另一个不同的对象。 但是引用则总是指向在初始化时被指定的对象,以后不能改变。string s1("Nancy"); string s2("Clancy"); string& rs = s1; // rs ... 阅读全文

posted @ 2012-10-30 20:01 GIS-MAN 阅读(186) 评论(0) 推荐(0)

c++ 参数传递 之引用形参
摘要:在函数内部对引用形参做 出的改变会影响到函数外部实参的改变引用形参的例子void swap(int &v1, int &v2) { int tmp = v2; v2 = v1; v1 = tmp; } 非引用形参void swap(int v1, int v2) { int tmp = v2; v2 = v1; // assigns new value to local copy of the argument v1 = tmp; }使用引用... 阅读全文

posted @ 2012-10-30 17:29 GIS-MAN 阅读(632) 评论(0) 推荐(0)

c++ 参数传递之 非引用形参
摘要:1 非引用实参每次调用函数时,都会重新创建该函数所有的形参,此时所传递的实参将会初始化对应的形参。 形参的初始化与变量的初始化一样:如果形参具有非引用类型,则复制实参的值,如果形参为引用类型(第 2.5 节),则它只是实参的别名。指针形参————————————————可以修改实参指针指向的值,但是不能修改实参指针函数的形参可以是指针(第 4.2 节),此时将复制实参指针,如果函数形参是非 const 类型的指针,则函数可通过指针实现赋值,修改指针所指向对象的值:void reset(int *ip) { *ip = 0; // changes the value ... 阅读全文

posted @ 2012-10-30 17:20 GIS-MAN 阅读(406) 评论(0) 推荐(0)

c++ 枚举
摘要:枚举成员值可以是不唯一的。 // point2d is 2, point2w is 3, point3d is 3, point3w is 4 enum Points { point2d = 2, point2w, point3d = 3, point3w }; 本例中,枚举成员 point2d 显式初始化为 2。下一个枚举成员 point2w 默认初始化,即它的值比前一枚举成员的值大 1。因此 point2w 初始化为 3。枚举成员 point3d 显式初始化为 3。一样,point3w 默认初始化,结果为 4。枚举的使用::Points pt3d = point3d; ... 阅读全文

posted @ 2012-10-30 16:47 GIS-MAN 阅读(177) 评论(0) 推荐(0)

c++ const
摘要:Const int bufSize=512// bufSize 以后不能修改,定义时必须初始化const std::string hi=“helloworld”在全局作用域声明的 const 变量是定义该对象的文件的局部变量。此变量只存在于那个文件中,不能被其他文件访问。通过指定 const 变更为 extern,就可以在整个程序中访问 const 对象:// file_1.cc // defines and initializes a const that is accessible to other files extern const int bufSize =... 阅读全文

posted @ 2012-10-30 16:42 GIS-MAN 阅读(186) 评论(0) 推荐(0)

c++ arrow operator ,, –> Operator,,,指针专属
摘要:C++ has an operator that can be used with a pointer to simplify the notation for specifying the members of a struct or a class. The arrow operator , -> , combines the actions of a dereferencing operator, * , and a dot operator to specify a member of a dynamic struct or class object that is p... 阅读全文

posted @ 2012-10-30 14:52 GIS-MAN 阅读(821) 评论(0) 推荐(0)

让c++ 函数返回一个数组
摘要:在c++中是不允许数组作为函数的返回值的int [] someFunction( ); //ILLEGAL要想实现函数返回一个数组,那返回对应数组里面类型的指针you must return a pointer to the array base type and have the pointer point to the array. So, the function declaration would be as follows: int* someFunction( ); //Legalint* doubler( int a[], int size){int* temp = new in 阅读全文

posted @ 2012-10-30 14:45 GIS-MAN 阅读(45815) 评论(0) 推荐(0)

c++ const 修饰数组
摘要://直接声明为 int a[], 这样会允许函数内部对a[] 进行修改void showTheWorld( int a[], int sizeOfa) { for ( int i = 0; i < sizeOfa; i++) cout << a[i] << " "; cout << endl; }如果 声明为const int a[], C++就不允许函数内部在对a[] ,进行修改了 void showTheWorld( const int a[], int sizeOfa) { ... 阅读全文

posted @ 2012-10-30 11:39 GIS-MAN 阅读(4816) 评论(0) 推荐(0)

c++ 继承
摘要:单继承 多继承class ImageBook:public Book { } class ImageBook: public Book, public Image { };virtual inheritance ://li例子如下class Book :virtual public Paper { };class Image : virtual public Paper { }class ImageBook: public Book, public Image { };// 只会出现一个 Pa... 阅读全文

posted @ 2012-10-30 10:50 GIS-MAN 阅读(169) 评论(0) 推荐(0)

导航