博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2011年8月18日

摘要: 调了一个下午还没有调好,估计今天脑袋要晕掉,过几天接着调。想想思路上有啥好的改进没// Console08172.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <assert.h>#include <math.h>using namespace std;const int N = 100;void Calc2BigNum(int num1[], int len1, int 阅读全文

posted @ 2011-08-18 20:50 ChessYoung 阅读(204) 评论(0) 推荐(0) 编辑

2011年8月17日

摘要: #include "stdafx.h"#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int line = __LINE__; //注意:LINE前后分别是两个下划线“-”(半角状态下) char * file = __FILE__; cout<<line<<endl; cout<<file<<endl; return 0;} 阅读全文

posted @ 2011-08-17 11:07 ChessYoung 阅读(322) 评论(0) 推荐(0) 编辑

摘要: 目前看到的比较好的方法是:#define MaxNum(a, b) (fabs((a)-(b)) == ((a)-(b))?(a):(b))这个定义也有问题,虽然说fabs参数为double类型,已经是足够用了,但在c++中有个重载的问题,其原型为double fabs( double x );如果输入的两个数都为int类型,编译就通不过。由此可见,不要用宏干这样的事情,实在是,没什么意义 阅读全文

posted @ 2011-08-17 10:59 ChessYoung 阅读(2289) 评论(0) 推荐(0) 编辑

2011年8月16日

摘要: 如果试图直接使用C++的成员函数作为回调函数将发生错误,甚至编译就不能通过。其错误是普通的C++成员函数都隐含了一个传递函数作为参数,亦即“this”指针,C++通过传递this指针给其成员函数从而实现程序函数可以访问C++的数据成员。这也可以理解为什么C++类的多个实例可以共享成员函数却-有不同的数据成员。由于this指针的作用,使得将一个CALL-BACK型的成员函数作为回调函数安装时就会因为隐含的this指针使得函数参数个数不匹配,从而导致回调函数安装失败。要解决这一问题的关键就是不让this指针起作用,通过采用以下两种典型技术可以解决在C++中使用回调函数所遇到的问题。这种方法具有通用 阅读全文

posted @ 2011-08-16 09:21 ChessYoung 阅读(2580) 评论(0) 推荐(0) 编辑

摘要: 注意的问题是:正负号;是否越界,也即是否全是数字;参数判断,一定要保证合法,不合法的中断运行#include "stdafx.h"#include <iostream>#include <assert.h>using namespace std;int atoi2(char *str);int main(void){ char *s = "+1a345"; int a = atoi2(s); cout << a; return 0;}int atoi2( char *str ){ assert(str != NULL) 阅读全文

posted @ 2011-08-16 08:54 ChessYoung 阅读(189) 评论(0) 推荐(0) 编辑

2011年8月15日

摘要: 某个字符串中有左右括号,和常见的数学式子一样,任何一个左括号都是从内向外的与它在右边、距离最近的右括号相匹配。编写一个程序找出无法匹配的左括号与右括号,并在下方标出来。自己模仿:#include "stdafx.h"#include <iostream>using namespace std;const int SIZE = 100;void ParCount(char line[], char error[], int &flags);int _tmain(int argc, _TCHAR* argv[]){ char line[] = "( 阅读全文

posted @ 2011-08-15 22:39 ChessYoung 阅读(268) 评论(0) 推荐(0) 编辑

摘要: #include <stdio.h>#include <stdarg.h>float average(int n_values,...){ va_list var_arg; int count; float sum = 0; /*准备访问可变参数*/ va_start(var_arg, n_values); /*添加取自可变参数列表的值*/ for(count = 0; count < n_values;count++) { sum += va_arg(var_arg, int); } /*完成处理可变参数*/ va_end(var_arg); return su 阅读全文

posted @ 2011-08-15 10:45 ChessYoung 阅读(152) 评论(0) 推荐(0) 编辑

2011年8月11日

摘要: //从一堆的数字中找到丢失的一个数字,前提是这些数字除了丢失的那一个之外其他//是成偶数个数出现的,方法采用异或#include "stdafx.h"#include <iostream>using namespace std;int XorF(int a[], int len);int _tmain(int argc, _TCHAR* argv[]){ int a[] = {3,3,5,3,3,5,5,5,4,1,4,1,6,7,6,7,9,11,9,11,4,4,4}; int Z = XorF(a, sizeof(a)/sizeof(int)); cout 阅读全文

posted @ 2011-08-11 23:02 ChessYoung 阅读(265) 评论(0) 推荐(0) 编辑

摘要: 学艺不精,唉,惭愧惭愧!又输了,竞技场的滋味啊 阅读全文

posted @ 2011-08-11 21:16 ChessYoung 阅读(109) 评论(0) 推荐(0) 编辑

摘要: #include "stdafx.h"#include <ObjBase.h>#include <iostream>using namespace std;void trace(const char *pMsg) { cout << pMsg << endl; }interface IX{ virtual void __stdcall Fx1() = 0; virtual void __stdcall Fx2() = 0;};interface IY{ virtual void __stdcall Fy1() = 0; vir 阅读全文

posted @ 2011-08-11 21:15 ChessYoung 阅读(274) 评论(0) 推荐(0) 编辑