C++
乔巴好萌
目前只会Go C++ python Java
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
c语言中format不同的数据匹配的不同数据格式
C/C++编译时,如果对应的参数类型和格式不匹配,经常会有warning,为了避免warning,我总结了下常见的的数据类型对应的格式,后期会不断丰富数据类型格式int %dlong %ldunsigned long%lulong long %lld或%lliunsigned long long原创 2013-03-13 22:43:54 · 1737 阅读 · 0 评论 -
C++默认成员函数使用说明
1) 默认构造函数2) 默认析构函数3) 拷贝构造4) 赋值函数5) 缺省取值6) 缺省取值(const)对于后2个,之前还真没注意到是操作符重载,现在记录下:#include using namespace std;class MyClass{public: MyClass(int value) { mValue =原创 2013-03-28 23:12:51 · 884 阅读 · 0 评论 -
C++中不能被继承的类的实现
首先,了解下什么是虚继承-- 为了解决菱形继承的多义性 #include using namespace std;class Animal{public: void foo() { cout "Animal foo"endl; }};class Mammal : public virtual Animal{};class W原创 2013-03-29 13:08:06 · 856 阅读 · 0 评论 -
如何检测CPU是大端还是小端
MSB 最高有效位LSB 最低有效位所谓的大端 值得是最高有效位放在最低地址小端,则是最低有效位放在最低地址#include int main(){ union ut{ short s; char c[2]; }u; if(sizeof(short) == 2) { u.s = 0x0102; fprintf(转载 2013-03-29 23:18:00 · 1067 阅读 · 0 评论 -
C++自定义链表操作实现
author openxmp@163.com链表操作:1) 插入2) operator []3) 翻转(递归)4) 翻转(非递归)5) 求长度#include using namespace std;#include templatetypename T>class List{ //A template-parame原创 2013-02-24 11:32:00 · 2162 阅读 · 0 评论 -
ACE_Profile_Timer用法
ACE_Profile_Timer的用法ACE_Profile_Timer提供了一个简易的计算资源使用情况的接口使用时声明如下对象:ACE_Profile_Timer timer;timer.start();//....your operationtimer.stop();ACE_Profile_Timer::ACE_Elapsed_Time elapse_ti原创 2013-03-19 16:51:50 · 2327 阅读 · 0 评论 -
int溢出的问题
今天,在论坛上看到一个帖http://bbs.youkuaiyun.com/topics/390397669?page=1#post-393964523后面有我的回复总结了下 获取与编译器相关的int、char、long的最大值的方法分别为1) 使用头文件 里面分别有关于最大、最小的char 、int、long的值。2) 分别将-1转换成对应的unsigned char原创 2013-03-19 21:38:33 · 4197 阅读 · 0 评论 -
有关C++对象与bool比较时的操作符重载
需要实现operator bool ()的重载。struct MyClass{ explicit operator bool() const { return true; } };如上:写了一个完整的例子#include using namespace std;class MyClass{public: MyClass(int valu原创 2013-03-25 22:23:57 · 8031 阅读 · 0 评论 -
求逆序数
输入一个整数,如83721,输出其逆序数12738#include using namespace std;int reverseNumber ( int input ){ int retval = 0; while ( input ) { int lowNumber = input % 10 ;原创 2013-03-27 21:35:06 · 991 阅读 · 0 评论 -
树的遍历
#include using namespace std;#include #include using std::stack;templatetypename T>struct Node{ Node(T value):mValue(value),mLeftChild(0),mRightChild(0) { } T mValu原创 2013-03-13 18:45:50 · 848 阅读 · 0 评论 -
vector和dequeue的push_back比较
/*本文比较了vector和dequeue差距,看来对vector使用时,在有大规模数据需要使用push_back时,应该使用reserve来重新设定空间大小。否则,使用vector的每次push_back时,vector会重新释放以前的数据,进行重新拷贝,造成不必要的开销。而dequeue的插入不会引人旧数据的释放,适合大规模数据的拷贝。*/ #include原创 2013-03-13 10:41:01 · 1661 阅读 · 0 评论 -
二叉树的层次遍历
8 / \ 6 10 / \ / \ 5 7 9 11 层次遍历输出结果: 8,6,10,5,7,9,11#include using std::deque;#include using namespace std;templatetypename T>struct TreeNode{publ原创 2013-03-11 22:31:24 · 914 阅读 · 0 评论 -
[APUE读书笔记] 有关exit 和_exit区别的比较
最近重新看了一下APUE, chapter 7中讲到进程终止有以下几种方式:1) 从main返回2) 调用exit3) 调用_exit或_Exit4) 最后一个线程返回5) 最后一个线程pthread_exit 其中,对于2,3的区别书上说的是"_exit很快进入内核模式,而exit则执行处理操作",为了更好的理解这句话,我编写了下面的测试例子.(见后面的代码示例)测试环境:ubuntu 11.原创 2013-02-16 09:50:43 · 1141 阅读 · 0 评论 -
句子翻转的STL实现
字符串翻转的例子输入如 A fox has jumped into the river输出为 river the into jumped has fox A#include #include using std::string;#include using std::vector;#include using name原创 2013-03-05 17:42:28 · 883 阅读 · 0 评论 -
有关C++ POD的一些问题记录
最近看见同事之前写了一个框架,涉及Windows/Linux平台,中间发现同事写的容器的类库中,有容器的插入操作. 当容器数据满时,重新按照2*capacity的大小重新分配数据,这里在拷贝数据的时候,采用了memcpy方法进行拷贝,而 模板实参大部分都是非POD的类,内部含有virtual函数,对于非POD的类对象,编译器往往会向其中插入一些不可见的数据, 导致使用memcpy进行数原创 2013-02-22 09:29:34 · 796 阅读 · 0 评论 -
C++快速排序模板法
#include #include using std::string;#include using namespace std;templatevoid mySwap( T & left, T & right ){ T tmp = left; left = right; right = tmp;}templateint partion( T array[] ,原创 2013-02-24 17:03:15 · 1055 阅读 · 0 评论 -
C++操作符重载总结
/** C++操作符重载时,首先找成员函数是否已经有相关实现,如果有相关的实现,则优先调用成员函数的操作符重载,如果没有的话,则调用全局的操作符重载. 总结: 1) 不可以重载的操作符 (1) :: (2) .* (3) ?: 2) 重载操作符必须有一个类类型或枚举类型,意思是不能重载内置的基本数据类型的操作符 3) 优先级和结合性是固定的 4) 不保证操作符原创 2013-02-23 13:09:45 · 874 阅读 · 0 评论 -
约瑟夫问题求解
问题描述:据说著名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人开始报数,每报数到第3人该人就必须自杀,然后再由下一个重新报数,直到所有人都自杀身亡为止。然而Josephus 和他的朋友并不想遵从,Josephu原创 2013-02-25 00:17:55 · 866 阅读 · 0 评论 -
gdb调试死锁线程
/** 死锁调试 1) -g参数 2) attach 3) info threads 4) thread + number切换到对应的线程或thread apply all bt全部设置断点*/#include #include #include void *workThread( void *arg ){ pthread_mut原创 2013-02-26 18:18:16 · 4314 阅读 · 0 评论 -
在二元树中找出和为某一值的所有路径
题目:输入一个整数和一棵二元树。从树的根结点开始往下访问一直到叶结点所经过的所有结点形成一条路径。打印出和与输入整数相等的所有路径。例如输入整数22和如下二元树 10 / \原创 2013-03-12 00:10:44 · 812 阅读 · 0 评论 -
C++字符串翻转操作
举例:I love cpp翻转后cpp love I 算法: 先翻转整个句子,再翻转每个单词 #include #include void reverseInPlace( char *input, int start, int end ){ char *s = input + start; char *e = input + end; w原创 2013-03-27 11:35:37 · 2635 阅读 · 0 评论
分享