
C/C++
Cryking
双重性格,一半喜静,一半喜动
展开
-
反汇编解析一段小代码(面试题)
#includeusing namespace std;struct S{ int a; int *p;};S s;int main(){ int *temp=&s.a; temp[0]=10; temp[1]=12; s.p=temp; s.p[1]=20; s.p[0]=120;//报错 return 0;}原创 2012-07-03 23:54:55 · 1284 阅读 · 0 评论 -
[C++]双向链表操作
头文件--定义基类、双向链表类、结点类#include "iostream.h" #include "string.h" class Object //定义抽象类 { public: Object(){} virtual int IsEqual(Object&)=0;//实现2个结点数据的比较 virtual void Show()=0;//输出一个结点的数据 virtual ~原创 2012-12-22 14:13:50 · 964 阅读 · 0 评论 -
[C++]内置类型变量在内存中的存放
#include #include using namespace std;int main(){ const int i=3; const int *p=&i; cout<<*(p)<<endl; const int j=9; cout<<*(p+1)<<endl; return 0;原创 2011-01-19 14:27:00 · 976 阅读 · 0 评论 -
统计电脑所有文件
没事无聊写着玩的,也就是熟练运用API而已,没什么技术可言...#include #include #include #include #include #include using namespace std; static int count=0; //记录文件个数 void FindInAll(string & Path,fstream & outfile)原创 2012-12-20 10:44:44 · 1022 阅读 · 0 评论 -
自己的Ping程序(MFC实现)
工具:VC6.0环境: WIN XP主要功能:输入远程主机的IP或者域名,输入ping的次数,点击ping,即可显示ping的结果,且自动将结果记录在日志文件ping_log.txt里。主要代码如下:void CPingDlg::OnPing() { // TODO: Add your control notification handler code原创 2012-07-08 12:52:20 · 6780 阅读 · 4 评论 -
[C++]linux下使用occi连接oracle遇到的两个错误
我的makefile如下:includepath=${ORACLE_HOME}/precomp/publicoccpath=${ORACLE_HOME}/oci/includelibpath=${ORACLE_HOME}/liblibfile=-L${libpath} #/usr/lib/libstdc++.so.5incfile=-I${includepath}occif原创 2013-07-24 01:04:13 · 3169 阅读 · 0 评论 -
N皇后问题的解决
来源于国际象棋中的皇后,通常叫8皇后问题,即在一个n×n的棋盘上摆放n个皇后,使其中任意两个皇后都不同列、同行和在一条斜线上。 #include using namespace std;#define N 4char board[N][N];int col[N]; //存储第i行对应的列的值,这样的(i,j)值满足当前棋盘上的皇后不能原创 2008-05-16 10:27:00 · 785 阅读 · 0 评论 -
API编程模版
#include LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow){ HWND hwnd;原创 2012-06-27 14:35:07 · 2068 阅读 · 2 评论 -
数字转换为金额(c实现)
//c代码:只实现基本功能////缺点:只支持万元以下的数值(这个是可以改进的),小数只有2位,只能到分////比较好的就是,连续的0只输出一个零////如:10010 输出:1万零1十#include "stdio.h"#include "conio.h"#include "string.h"int main(){int i=1,j=1,k;char *y={"\0"原创 2012-07-08 13:43:08 · 1245 阅读 · 0 评论 -
C++实现多文件中查找多个字符串
#include #include #include #include #include #include using namespace std;const int EXT_MAXSIZE=5; //扩展名的最大长度,包括"."const int EXT_ARRAY_SIZE=20; //扩展名数组的大小string EXT[EXT_ARRAY_SIZE];原创 2012-08-29 13:06:04 · 6247 阅读 · 0 评论 -
c++基础知识(容易面试到的)
构造函数与析构函数是否能为虚函数?大家都知道析构函数可以是虚函数,构造函数不能为虚函数。为什么构造函数不能为虚函数呢?1。从存储空间角度虚函数对应一个vtable,这大家都知道,可是这个vtable其实是存储在对象的内存空间的。问题出来了,如果构造函数是虚的,就需要通过vtable来调用,可是对象还没有实例化,也就是内存空间还没有,怎么找vtable呢?所以构造函数不能是虚函数。2原创 2012-07-08 14:22:00 · 3180 阅读 · 0 评论 -
向量表解决约瑟夫问题
向量表定义vector.h#ifndef VECTOR_H#define VECTOR_H#includeusing namespace std;//向量表template class Vector{ private: T *elements;//数组 int ArraySize,VectorLength; void GetArray();原创 2012-07-27 16:47:08 · 874 阅读 · 0 评论 -
大数相加,结果可精确到1000位(利用数组)
电脑丢了,没代码了,就剩下这张图片了。。。发现自己以前写代码没一点注释,现在自己都快看不懂了。。。菜鸟级的代码,大大莫笑!原创 2012-07-08 13:38:17 · 1148 阅读 · 0 评论 -
9x9乘法表
//C++打印9*9乘法表#include#includeusing namespace std;int main(void){ int i,j; cout<<" "; for(i=1;i<10;i++) cout<<i<<setw(8);//横排显示1-10十个数字并控制输出8个空格字符宽度 cout<<'\n'; for(i=1;i原创 2012-06-27 15:15:00 · 2509 阅读 · 0 评论 -
全局静态变量及局部静态变量
#includeusing namespace std;static int j;//存放在程序全局区,在main函数之前就映射到内存的数据段, //以下任何地方都可调用,默认初始化为0void fun1(void){ static int i = 0;//局部静态变量,生命周期为整个源程序,作用域为该函数(fun1)内 i++; cout<<"i="<<原创 2012-06-27 14:49:55 · 755 阅读 · 0 评论 -
C++替换文件中指定的内容
/*实现替换文件中指定的内容----Created by cryking------------2012.02.12--------*/#include#include#include#includeusing namespace std;char *strstr_rep(char *source,char *old,char *ne)//字符替换{ char *org=so原创 2012-06-30 18:41:03 · 19134 阅读 · 1 评论 -
C++基础01
//公式求π//π=16arctan(1/5)-4arctan(1/239)//arctan(x)公式arctan(x)=x/1-x*x*x/3+x*x*x*x*x/5+...=∑(-1)的n次方*x的2n+1次方/2n+1#includeusing namespace std;int main(){ double a,b; double arctan(double x); a原创 2012-07-15 00:06:30 · 1129 阅读 · 0 评论 -
C++基础02
//求1000以内的回文数//回文数:一个数正向输出和逆向输出都是本身,如121,131。。。#include#include //setw needusing namespace std;bool huiWen(long n);int main(){ long n=10,i=0; while(n++<10000) { if(huiWen(n)) { co原创 2012-07-15 00:08:11 · 622 阅读 · 0 评论 -
c++基础03
//每人分别拿3张牌(1-13),比3张牌的总点数大小#include#include#includeusing namespace std;int DianComp();int main(){ char ch; int xm; int xg; while(1) {cout<<"---------游戏开始---------"<<endl; c原创 2012-07-15 00:13:46 · 599 阅读 · 0 评论 -
c++基础04
//模版的简单示例#includeusing namespace std;templateT s(T x, T y){ return x*y;}int main(){ cout<<s(3,5)<<endl; cout<<s(2.2,52.2)<<endl; return 0;}原创 2012-07-15 00:18:17 · 670 阅读 · 0 评论 -
螺旋矩阵(c实现)
#include#define N 10int main(){ int c=0,i=0,j=0,out=1,n,z; int a[N][N]={0};/* 初始化下数组*/ printf("请输入数组维数:"); scanf("%d",&n); z=n*n; while(out<=z) { i=0; /*每轮后初始化下i,j */ j=0; for(i+=c,j原创 2012-07-08 13:53:22 · 8357 阅读 · 0 评论