代码改变世界

随笔档案-2012年03月

C++抽象类的纯虚函数

2012-03-31 22:25 by youxin, 7469 阅读, 收藏,
摘要: 1,定义: 纯虚函数是在基类中声明的虚函数,它在基类中没有定义,但要求任何派生类都要定义自己的实现方法。在基类中实现纯虚函数的方法是在函数原型后加"=0" ,同 java中抽象方法类似virtualvoidfuntion1()=0二、引入原因:1、为了方便使用多态特性,我们常常需要在基类中定义虚拟函数。2、在很多情况下,基类本身生成对象是不合情理的。例如,动物作为一个基类可以派生出老虎、孔雀等子类,但动物本身生成对象明显不合常理。 为了解决上述问题,引入了纯虚函数的概念,将函数定义为纯虚函数(方法:virtualReturnTypeFunction()=0;),则编译器要求 阅读全文

fatal error C1083: Cannot open precompiled header file: 'Debug/2_1.pch': No such file or directory

2012-03-31 18:34 by youxin, 746 阅读, 收藏,
摘要: fatal error C1083: Cannot open precompiled header file: 'Debug/2_1.pch': No such file or directory看下面的一段代码:#include<stdafx.h>#include<windows.h>#include<resource.h> int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,... 阅读全文

fatal error C1083: Cannot open include file: 'resource.h': No such file or directory

2012-03-31 18:00 by youxin, 3750 阅读, 收藏,
摘要: 发生错误:fatal error C1083: Cannot open include file: 'resource.h': No such file or directoryvc6.0在创建window应用程序时,提供了三种选择,1,一个空工程 ---No files will be created or added to the project.2.一个简单的win32应用程序 --Pre Compiled Header: Stdafx.h and Stdafx.cpp.3,一个典型的win32应用程序 --Pre Compiled Heade... 阅读全文

转:c++ virtual function

2012-03-30 15:12 by youxin, 762 阅读, 收藏,
摘要: C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class. The concept of c++ virtual functions is different fromC++ Function overloading.C++ Virt. 阅读全文

C++virtual 虚函数详解

2012-03-30 15:05 by youxin, 570 阅读, 收藏,
摘要: 首先看一下程序,猜猜运行结果是什么?#include<iostream>using namespace std;class Animal{public: Animal(int height,int weight) { cout<<"Animal construct"<<endl; } ~Animal() { cout<<"Animal destruct"<<endl; } void eat() { cout<<"Animal's eat"<<e 阅读全文

在线编译器介绍

2012-03-30 12:12 by youxin, 583 阅读, 收藏,
摘要: 最出名在线C/C++编译网站:http://www.dinkumware.com/exam/default.aspx支持多种语言的在线编辑器,个人觉得蛮好;http://codepad.org/网上有许多在线C++编译器。你可以利用它们对你的代码针对各种C++编译器进行兼容性测试,而不需要购买和安装这些编译器。在这里给大家推荐几款,可以根据需要自行选择使用:1.http://www.dinkumware.com/exam/default.aspx推荐星级:★★★★是否需注册:否优点:网页界面简洁,多种类库支持,对编译后信息统计准确,推荐使用。缺点:支持语言种类较少。2、http://codep 阅读全文

windows新建一个窗口程序示例

2012-03-30 10:20 by youxin, 698 阅读, 收藏,
摘要: 程序步骤:1,winmain函数定义2,创建一个窗口3,进行消息循环4,编写窗口过程函数。看代码,如下:#include <windows.h>#include <stdio.h>LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter);int WINAPI WinM... 阅读全文

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

2012-03-30 10:14 by youxin, 1804 阅读, 收藏,
摘要: 转:出现以下错误:fatal error LNK1120: 1 unresolved externals错误可能原因:1、程序中缺少lib文件,在project -> setting里的link中加入所需lib文件即可。2、在程序中函数只有声明没有定义,而导致这个问题的很可能的原因是在函数定义时把函数名称写错了,(这是常见的) 所以以后一定要在写函数定义时复制函数声明中的函数名,以避免类似不必要的麻烦发生。LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main在创建MFC项目时,如果没有设置好项目参数, 阅读全文

c语言NULL和0区别及NULL详解

2012-03-27 18:46 by youxin, 35155 阅读, 收藏,
摘要: 先看下面一段代码输出什么:#includeint main(){ int *p=NULL; printf("%s",p); }输出 ,单步调试可以看出执行int *p=NULL,p的值为0x00000000,可以看出,NULL在实际底层调用中就是0,在C语言中,NULL和0的值都是一样的,但是为了目的和用途及容易识别的原因,NULL用于指针和对象,0用于数值对于字符串的结尾,使用'\0',它的值也是0,但是让人一看就知道这是字符串的结尾,不是指针,也不是普通的数值在不同的系统中,NULL并非总是和0等同,NULL仅仅代表空值,也就是指向一个不被使用的地址,在 阅读全文

C语言fgets()函数

2012-03-27 18:02 by youxin, 1472 阅读, 收藏,
摘要: char * fgets ( char * str, int num, FILE * stream );Get string from stream 从文件流读取字符串Reads characters fromstreamand stores them as a C string intostruntil (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first. 存够n-1个字符或遇到换行符或到文件末尾 结束。A newline ch 阅读全文

DirectX 安装和vs2010配置

2012-03-24 20:30 by youxin, 1793 阅读, 收藏,
摘要: 先看看wikipediadirectx解释;(全称:DirecteXtension,简称DX)是由微软公司创建的多媒体编程接口。由C++编程语言实现,遵循COM。其API包含DirectX Graphics、DirectPlay、DirectSound、DirectInput、DirectSetup等部分(Direct3D与DirectDraw已整合成DirectX Graphics)、DirectMusic、DirectPlay。被广泛使用于Microsoft Windows、Microsoft Xbox和Microsoft Xbox 360电子游戏开发,并且只能支持这些平台。目前最新版本为 阅读全文

vc6.0怎么调整工作空间到左边??

2012-03-24 01:26 by youxin, 811 阅读, 收藏,
摘要: 搞了几个小时,真是烦死人了,要么全屏,要么不显示,怎么只显示在左边? 阅读全文

转:C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法

2012-03-22 22:16 by youxin, 591 阅读, 收藏,
摘要: C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法学C++的时候,这几个输入函数弄的有点迷糊;这里做个小结,为了自己复习,也希望对后来者能有所帮助,如果有差错的地方还请各位多多指教(本文所有程序均通过VC 6.0运行)1、cin2、cin.get()3、cin.getline()4、getline()5、gets()6、getchar()附:cin.ignore();cin.get()//跳过一个字符,例如不想要的回车,空格等字符1、cin>>用法1:最基本,也是最常用的用法,输入一个数字:#include using na 阅读全文

C++cin处理空格问题

2012-03-21 22:21 by youxin, 8215 阅读, 收藏,
摘要: 仔细分析下面程序 #include<iostream>using namespace std;#include<string>int main(){ string str="jack bullshit jack"; { string bullshit="bullshit"; string bush="bush"; size_t pos=str.find(bullshit,0); size_t length=8; if(pos!=string::npos) str.r... 阅读全文

c多个空格转成一个空格

2012-03-21 17:12 by youxin, 703 阅读, 收藏,
摘要: 主要思想是用一个计数器记录空格的数,程序如下:#include <stdio.h> void main() { int flag=1;/*当前不是空格,标志*/ char ch; int j=0;/*记数器*/ ch=getchar(); while(ch!=EOF) { if(ch==' ') { flag=0; j++; } else { flag=1; j=0; } if(!(flag==0&&j> 1)) putchar(ch); ch=getchar(); } } 还有一个去掉所以空格的好办法:#include<stdio.h& 阅读全文

c++ string::size详解

2012-03-18 14:21 by youxin, 4319 阅读, 收藏,
摘要: C++ string::size_type 类型intmain(){stringstr("HelloWorld!\n");cout<<"Thesizeof"<<str<<"is"<<str.size()<<"characters,includingthenewline"<<endl;return0;}从逻辑上来讲,size()成员函数似乎应该返回整形数值,或是无符号整数。但事实上,size操作返回的是string::size_type类型的值。 阅读全文

fatal error LNK1120: 1 个无法解析的外部命令

2012-03-18 13:48 by youxin, 3550 阅读, 收藏,
摘要: 错误消息number 个无法解析的外部命令错误 LNK1120 为您提供该链接的无法解析的外部对象数 (number)。导致无法解析的外部对象的条件由错误LNK2001描述,此错误出现在该错误信息之前(对每个无法解析的外部对象都出现一次)。虽然msdn上面说了很多原因,但我的是,新建项目时,可能没有选择控制台应用程序,重新建立了控制台应用程序,运行就成功了。 阅读全文

Tower of hanoi问题学习

2012-03-17 00:26 by youxin, 381 阅读, 收藏,
摘要: hanoi问题描述如下:三根杠,a,b,c,a盘上有n个盘子,盘的尺寸由下到上依次变小要把n个盘子由a杆借助c杆移动到b杆,要求有两条:1,依次只能移动一个盘2,不允许大盘放在小盘上面用递归解题方法如下:程序如下:#include<stdio.h>void hanoi(int n,char a,char b,char c);int main(){ int n; printf("请输入盘子的个数\n"); scanf("%d",&n); hanoi(n,'a','b','c');}void 阅读全文

算法导论之三:快速排序

2012-03-16 22:39 by youxin, 215 阅读, 收藏,
摘要: x 阅读全文

vc下找不到#include <graphics.h>

2012-03-16 19:49 by youxin, 20550 阅读, 收藏,
摘要: 如果头文件有这个,#include <graphics.h>,编译时会显示Cannot open include file: 'graphics.h': No such file or directory原因是graphics.h是Tc中专有的,<graphics.h>这个头文件不是标准C的头文件,vc下没有这个头文件,画图用控件来。还是有办法在vc下用的,就是把这个头文件和相关文件放在相应的lib和include目录下,有人制作了一个软件包,EasyX_2011惊蛰版http://www.easyx.cn,里面有头文件和安装方法,我只是把文件放在对应目 阅读全文

horner's rule霍纳法则及综合除法

2012-03-15 23:15 by youxin, 1281 阅读, 收藏,
摘要: 首先参考 horner's rule:http://en.wikipedia.org/wiki/Horner_scheme在synthetic divisions :http://en.wikipedia.org/wiki/Ruffini%27s_rulepn(x)=anx^n+a(n-1)*X^(n-1)+.....+a1*x+a0;归纳:1基础部:n=0; 有p0=an;2,归纳不:对任意的k,1using namespace std;float horner(int a[],float x,int n){ float result=0; for(int i=n;i>=0;i 阅读全文

基于递归的整数幂的计算

2012-03-15 21:26 by youxin, 760 阅读, 收藏,
摘要: 首先来看一个简单的计算n阶乘的例子:int factorial(int n){ if(n==0) return 1; else return n*factorial(n-1);}程序虽然简单,确反应了递归的基本思想。计算整数幂的的函数,如求a的n次幂。要分n为odd和even1.odd a^n=a^(n/2) * a^(n/2)*a;2.even a^n=a^(n/2)*a^(n/2)基于这点源码如下:#includeint power(int a,int n){ if(a%2==0) { if(n==1) ... 阅读全文

VS2010安装帮助文档

2012-03-14 21:19 by youxin, 1580 阅读, 收藏,
摘要: 刚装vs2010事系统被没有自动安装msdn,msdn帮助文档是在ProductDocumentation文件夹下,启动vs2010,选择帮助==》manage help setting=>,然后选择光盘文件夹ProductDocumentation下的HelpContentSetup.msha,然后有提示安装的帮助项目,帮你想要的安装项目选上就可以了。 有一个问题,我装完后按F!还是跳转到网络版的msdn,怎么回事?最后经过一阵折腾,终于发现了,原来我的帮助文档首选的是网络版本,所以虽然本地有,可是总是跳到网络版本。选择mange help setting 点击右上角的设置(不起眼,很 阅读全文

php 产生验证码

2012-03-11 21:52 by youxin, 323 阅读, 收藏,
摘要: <?php session_start();header("Content-type:image/png");srand((double)microtime()*1000000);$imagewidth=160;$imageheight=40;$image=imagecreate($imagewidth,$imageheight);$background_color=imagecolorallocate($image,200,200,200); //gray$white = imagecolorallocate($image, 255, 255, 255);$blac 阅读全文

imagecreate()与imagecreatetruecolor()区别

2012-03-11 17:47 by youxin, 2088 阅读, 收藏,
摘要: 首先让我们来看下官方文档的说明: imagecreate—Create a new palette based imageresourceimagecreate(int$width,int$height)imagecreate()returns an image identifier representing a blank image of specified size.We recommend the use ofimagecreatetruecolor(). imagecreatetruecolor—Create a new true color imageresourceimagec. 阅读全文

php mail函数一段好的代码

2012-03-10 15:14 by youxin, 378 阅读, 收藏,
摘要: <?php include('includes/title.inc.php'); ?><?php if(array_key_exists('send',$_POST)&&!$emaliSent){ $to = '1suming1@gmail.com,1suming@sina.com'; // use your own email address $subject = 'Feedback from Japan Journey site'; // process the $_POST variable 阅读全文

基于递归的插入排序

2012-03-09 12:54 by youxin, 3595 阅读, 收藏,
摘要: 插入排序类似玩扑克牌,每次把抽到的牌插入到已排好序的牌中,使之大小有序。直接插入排序(Insertion Sort)的基本思想是:每次将一个待排序的记录,按其关键字大小插入到前面已经排好序的子序列中的适当位置,直到全部记录插入完成为止。设数组为a[0…n-1]。1. 初始时,a[0]自成1个有序区,... 阅读全文