随笔分类 -  技术-编程-C/C++

摘要:1.定义struct template 2.在类模板外定义各方法 阅读全文
posted @ 2019-01-18 07:06 super行者
摘要:#include #include #include using namespace std; template class my_binder1st { public: my_binder1st(const Operation op, const Para first): m_op(op), m_first(first) { } Para operato... 阅读全文
posted @ 2019-01-06 09:16 super行者
摘要:函数对象,就是一个重载了"()"运算符的类的对象,它可以像一个函数一样使用。 STL中提供了一元和二元函数的两种函数对象:(都是模板) 一元函数对象: 二元函数对象: 下面是一段示例代码: 另一段示例代码: 阅读全文
posted @ 2019-01-05 20:27 super行者
摘要:运行后屏幕输出为:说明出现异常后auto_ptr指向的对象的析构函数仍然被执行了。 如果把上面代码中注释掉的代码打开,如下: 执行后屏幕显示如下:因为没有运用auto_ptr而用的裸指针,可以看到析构函数没有被调用 阅读全文
posted @ 2019-01-05 19:23 super行者
摘要:/* erase()删除指定元素,元素个数减1,即size-- remove()同时删除所有指定值的元素,其它元素前移补位,但元素总个数不变(size不变) */ #include #include #include using namespace std; template void print (vector &x) { typename vector::i... 阅读全文
posted @ 2019-01-04 22:33 super行者
摘要:#include #include #include using namespace std; /* demonstrate algorithm: find, for_each demonstrate reverse_iterator */ void print (int x) { cout d; for (int i=1; i::iterator p... 阅读全文
posted @ 2019-01-04 20:37 super行者
摘要:#include #include #include #include #include #include using namespace std; int main() { // demonstrate reverse an int array int a[4] = {3,2,4,1}; reverse(a,a+4); cout... 阅读全文
posted @ 2019-01-03 19:55 super行者
摘要:#include #include using namespace std; bool fncomp (char lhs, char rhs) {return lhs>rhs;} struct classcomp { bool operator() (const char& lhs, const char& rhs) const { return lhs> maps... 阅读全文
posted @ 2019-01-02 21:44 super行者
摘要:#include #include using namespace std; int main() { set st; st.insert("apple"); st.insert("orange"); st.insert("strawberry"); st.insert("peach"); st.insert("orange");... 阅读全文
posted @ 2019-01-02 21:03 super行者
摘要:#include #include #include #include #include using namespace std; int main() { stack> s; queue> q; // the default container of queue is deque for (int i = 0; i < 10; i++) { ... 阅读全文
posted @ 2018-12-28 06:42 super行者
摘要:Vector: 动态数组,内存中一整块连续区域。支持.reserve()和.capacity()。为提高效率,最好在添加元素之前用.reserve()分配好容量。插入删除操作越靠近数组首部效率越低。 deque(double ended queue): 动态数组,内存中多段连续区域拼凑。不支持res 阅读全文
posted @ 2018-12-28 05:13 super行者
摘要:#include #include #include using namespace std; template bool decreOrder(T &a, T &b) { return (a bool increOrder(T &a, T &b) { return (a > b); } template void Sort(vector & v, bool (*... 阅读全文
posted @ 2018-12-27 05:36 super行者
摘要:参考本博客中链接 《C++ vector 删除符合条件的元素》 阅读全文
posted @ 2018-12-27 04:45 super行者
摘要:#include using namespace std; template bool increSort(T &a, T &b) { return (a > b); } template bool decreSort(T &a, T &b) { return (a void Sort(T* array, int len, bool(*compare)(T&, T&)) ... 阅读全文
posted @ 2018-12-25 07:39 super行者
摘要:#include #include using namespace std; template class Stack { public: Stack() { } ~Stack() { } void push(T &e) { m_list.push_front(e); } void pop()... 阅读全文
posted @ 2018-12-25 06:37 super行者
摘要:#include #include using namespace std; // rever letters of a string char * strRevert1 (char * src) { if (src == NULL) return NULL; int len = strlen(src); for (int i=0; i= pWord); ... 阅读全文
posted @ 2018-12-23 19:19 super行者
摘要:#include using namespace std; unsigned int strlen1(const char * str) { const char * p = str; while (*p++ != '\0'); return (p-1-str); } int main() { char a[] = "12345"; cout << st... 阅读全文
posted @ 2018-12-23 19:19 super行者
摘要:#include #include using namespace std; bool checkRevStr (const char * src) { if (src == NULL) return false; const char * end = src + strlen(src) - 1; while (*src++ == *end--); retur... 阅读全文
posted @ 2018-12-23 19:18 super行者
摘要:#include #include using namespace std; int strcmp1 (const char * a, const char * b) { int ret = 0; while (!(ret=*a-*b) && *b) { ++a; ++b; } return (ret>0)?(1):((... 阅读全文
posted @ 2018-12-23 19:17 super行者
摘要:#include #include using namespace std; const char * findFirstLongestStr (const char * src, const char * des, unsigned int & count) { if (src==NULL || des==NULL) return NULL; int desLen = st... 阅读全文
posted @ 2018-12-23 19:16 super行者