上一页 1 ··· 3 4 5 6 7 8 下一页
该文被密码保护。 阅读全文
posted @ 2013-05-22 13:31 herizai 阅读(1) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2013-05-22 12:56 herizai 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 用c的方式实现栈用C++数据抽象的方式实现栈#include<stdio.h>structstruct Stack{};void StackInit(struct Stack* stack){stack->head=NULL;stack->size=0;}void StackPush(structStack*stack,const int data){struct Link* node;node=(struct Link*)malloc(sizeof(struct Link));assert(node!=NULL);node->data=data;node-> 阅读全文
posted @ 2013-05-22 12:52 herizai 阅读(110) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2013-05-22 11:44 herizai 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 如果已经有C语言基础的话,我这有三个选项,难度依次递增(Windows平台):使用命令行界面(就是那个黑框框),拼接成游戏界面。这个只需要去了解一下Windows的Console API就可以完成简单的游戏。好处是不需要太多额外的知识,简单易学。如果只是准备考写小游戏锻炼C语言水平,以后并不打算从事游戏开发的话建议选择。效果如下:主要利用函数SetConsoleCursorPosition和清屏就可以完成动画,模拟GUI~还可以改颜色噢,没有做不到只有想不到~~~如果你以后打算了解一下游戏开发的内容或者说对游戏品质有较高的要求的话,建议去选择一款2D游戏引擎,基本上可以完成一些比较复杂的游戏( 阅读全文
posted @ 2013-05-21 22:59 herizai 阅读(421) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2013-05-19 13:05 herizai 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 比如要将数组 int a[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};的元素循环右移动4那么 结果为 {9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8};显然最高效的方法是int temp=a[1];a[1]=a[9];a[9]=a[5];a[5]=temp; temp=a[2];a[2]=a[10];a[10]=a[6];a[6]=temp; temp=a[3];a[3]=a[11];a[11]=a[7];a[7]=temp; temp=a[4];a[4]... 阅读全文
posted @ 2013-05-19 09:04 herizai 阅读(635) 评论(0) 推荐(0) 编辑
摘要: #include <windows.h>int main(){ShellExecute(NULL,"open","http://baidu.com",NULL,NULL,SW_SHOWNORMAL);return 0;} 阅读全文
posted @ 2013-05-18 10:55 herizai 阅读(173) 评论(0) 推荐(0) 编辑
摘要: http://202.197.224.59/OnlineJudge2/index.php/User/registerhttp://acmpj.zstu.edu.cn/JudgeOnline/problemlist?volume=24http://acm.hdu.edu.cn/listproblem.php?vol=1http://acm.hdu.edu.cn/diy/contest_show.php?cid=18709 阅读全文
posted @ 2013-05-18 09:16 herizai 阅读(226) 评论(0) 推荐(0) 编辑
摘要: http://sourceforge.net/projects/libusb-win32/files/ 阅读全文
posted @ 2013-05-18 00:43 herizai 阅读(125) 评论(0) 推荐(0) 编辑
摘要: C++继承可以是单一继承或多重继承,每一个继承连接可以是public,protected,private也可以是virtual或non-virtual。然后是各个成员函数选项可以是virtual或non-virtual或pure virtual。本文仅仅作出一些关键点的验证。 public继承,例如下:1 class base2 {...}3 class derived:public base4 {...} 如果这样写,编译器会理解成类型为derived的对象同时也是类型为base的对象,但类型为base的对象不是类型为derived的对象。这点很重要。那么函数形参为base类型适用于... 阅读全文
posted @ 2013-05-16 18:05 herizai 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 位域(Bit-fields)分析 位域是c++和c里面都有的一个概念,但是位域有一点要注意的有很多问题我们一样样的看:一、大端和小端字节序实际就是起始点该怎么确定。先看一个程序: 1: union { 2: struct 3: { 4: unsigned char a1:2; 5: unsigned char a2:3; 6: unsigned char a3:3; 7: }x; 8: unsigned char b; 9: }d; 10: 11: int... 阅读全文
posted @ 2013-05-16 18:02 herizai 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 1、vs2010中的debug菜单中常用命令ContinueF5开始调试Stop DebugingShift+F5停止调试Toggle BreakpointF9设置断点Step OverF10单步(不进入函数)Step InfoF11单步(进入函数)Step OutShift+F11跳出函数Delete All BreakpointsCtrl+shift+F9删除所有断点2、设置断点在程序编辑窗口的左侧灰色区域点击对应的语句位置就可以设置一个断点或都按F9。3、按F5开始执行调试,程序会在设置的断点处停止。4、按F10或F11可进行单步测试。 阅读全文
posted @ 2013-05-16 17:52 herizai 阅读(732) 评论(0) 推荐(0) 编辑
摘要: malloc和free(及其变体)会产生问题的原因在于它们太简单:他们不知道构造函数和析构函数。假设用两种方法给一个包含10个string对象的数组分配空间,一个用malloc,另一个用new: string *stringarray1 =static_cast<string*>(malloc(10 * sizeof(string)));string *stringarray2 = new string[10];其结果是,stringarray1确实指向的是可以容纳10个string对象的足够空间,但内存里并没有创建这些对象。而且,如果你不从这种晦涩的语法怪圈(详见条款m4和m8的 阅读全文
posted @ 2013-05-16 17:32 herizai 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 百度贴吧测试部门实习生电话面试1.内存如何分配?答:内存分配方式有三种:(1)从静态存储区域分配。内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在。例如全局变量,static变量。(2)在栈上创建。在执行函数时,函数内局部变量的存储单元都可以在栈上创建,函数执行结束时这些存储单元自动被释放。栈内存分配运算内置于处理器的指令集中,效率很高,但是分配的内存容量有限。(3)从堆上分配,亦称动态内存分配。程序在运行的时候用malloc或new申请任意多少的内存,程序员自己负责在何时用free或delete释放内存。动态内存的生存期由我们决定,使用非常灵活,但问题也最多。参考:htt 阅读全文
posted @ 2013-05-16 17:29 herizai 阅读(265) 评论(0) 推荐(0) 编辑
摘要: malloc和free(及其变体)会产生问题的原因在于它们太简单:他们不知道构造函数和析构函数。假设用两种方法给一个包含10个string对象的数组分配空间,一个用malloc,另一个用new: string *stringarray1 =static_cast<string*>(malloc(10 * sizeof(string)));string *stringarray2 = new string[10];其结果是,stringarray1确实指向的是可以容纳10个string对象的足够空间,但内存里并没有创建这些对象。而且,如果你不从这种晦涩的语法怪圈(详见条款m4和m8的 阅读全文
posted @ 2013-05-16 17:27 herizai 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 先看一下代码:char *t=NULL;char * strcopy(const char * p,const char m){ int i,j; char q[40]={"123456789"};-------------------------------1. char *q=malloc(40);--------------------------------2.static char q[40]="123456789";----------------------3. for(i=m-1,j=0;p[i]!='/0';i++,j+ 阅读全文
posted @ 2013-05-16 17:25 herizai 阅读(213) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>class Boat;//需要声明,因友元用到class Car{ int size;public: void setSize(int j){size=j;} int getSize(){return size;} friend int leisure(int time,Car& aobj,Boat&bobj);//};class Boat{ int size;public: void setSize(int j){size=j;} int getSize(){return size;} friend int leisure(in 阅读全文
posted @ 2013-05-16 17:12 herizai 阅读(137) 评论(0) 推荐(0) 编辑
摘要: C++操作符的优先级操作符及其结合性功能用法LLL::::::全局作用域类作用域名字空间作用域::nameclass::namenamespace::nameLLLLL.->[]()()成员选择成员选择下标函数调用类型构造object.memberpointer->membervariable[expr]name(expr_list)type(expr_list)RRRRR++--typeidtypeid显示强制类型转换后自增操作后自减操作类型ID运行时类型ID类型转换lvalue++lvalue--typeid(type)typeid(expr)cast_name<type 阅读全文
posted @ 2013-05-16 16:56 herizai 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 简单,用类名实例化一个对象,即可作为参数进行传递!定义一个类class A;实例化类对象A a;定义 函数 int f(A x){};函数调用void main(){ f(a);//a为参数}一个函数(包括普通函数和成员函数)可以被多个类声明为“朋友”,可以引用多个类中的私有数据. 一个函数相当于一个接口,跟所定义的类无关,类中中只是使用它而已,如果不是main函数中定义的函数所有地方都可以使用,给它定义为友元只不过是为了这个函数能使用当前类的私有成员//=====================================// EX0807.cpp// 友元改成普通函数//===... 阅读全文
posted @ 2013-05-16 13:34 herizai 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 1 * 栈基本操作 2 * 08/25/2010 3 * 参考自严蔚敏等《数据结构(C语言版)》清华大学出版社 4 */ 5 #include 6 #include 7 #include 8 using namespace std; 9 10 // constant definition 11 static const int S... 阅读全文
posted @ 2013-05-16 11:19 herizai 阅读(207) 评论(0) 推荐(0) 编辑
摘要: stdlib.h:stdlib.h里面定义了五种类型、一些宏和通用工具函数。 类型例如size_t、wchar_t、div_t、ldiv_t和lldiv_t; 宏例如EXIT_FAILURE、EXIT_SUCCESS、RAND_MAX和MB_CUR_MAX等等; 常用的函数如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等等。time.htime.h是C/C++中的日期和时间头文件。得到从程序启动到此次函数调用时累计的毫秒数。NVIDIA面试笔试题之一:assert.h是c标准库的一 阅读全文
posted @ 2013-05-16 11:18 herizai 阅读(214) 评论(0) 推荐(0) 编辑
摘要: setw控制符只对后面紧跟的起作用,而setfill控制符一旦设定,就会对后面一直起作用,直到你重新设置。 我给你举个例子,看下面这段程序: #include <iostream> using namespace std; #include <iomanip> int main() { cout<<setw(8)<<setfill('*')<<123<<endl; cout<<setw(8)<<456<<endl; return 0; } 输出结果是: *****123 阅读全文
posted @ 2013-05-16 10:53 herizai 阅读(1894) 评论(0) 推荐(0) 编辑
摘要: #include<fstream> #include<iostream> #include<string> using namespace std; void main() { char ch; char c[10]; ifstream in("zsm.txt"); ofstream out("lala.txt"); for(string str;getline(in,str);) { out<<str<<endl; strcpy(c,str.c_str()); //c_str()是string 阅读全文
posted @ 2013-05-15 22:50 herizai 阅读(208) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<sstream>using namespace std;int main(){ string str1,str2; char *p1,*p2; int min; cout<<"请输入两个字符串:"; cin>>str1>>str2; p1=&st 阅读全文
posted @ 2013-05-14 22:35 herizai 阅读(521) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std; class A{};class B{public: operator A()//重载操作符,这个是操作符,从B 类型 转为A类型,{ return A(); }}; void func(A){ cout<<"this is from func"<<endl;}void main(){ B b; func(b);}class B{double a;public:operator double(){return a;}}int main(){B b;double 阅读全文
posted @ 2013-05-14 22:03 herizai 阅读(110) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<iomanip>using namespace std;int a[3][3];//声明二维数组void print();void change(int (*a)[3]);//参数为指针数组int main(){ cout<<"请输入一个3*3的矩阵"<<'\n'; for(int i=0;i<3;++i) for(int j=0;j<3;++j) { cin>>a[i][j]; } cout<<"写成3*3形式 阅读全文
posted @ 2013-05-14 22:00 herizai 阅读(152) 评论(0) 推荐(0) 编辑
摘要: #include "kmp.h"//一般的kmp算法求模式串匹配的位置,返回值下标从1开始计算intkmp(conststring&s,conststring&t){inti(0),j(0);int*next=newint;GetNext(t,next);//思想同求next类似while(i<s.length()&&j<(int)t.length())//此处注意,t.length()返回的是无符型,而j=-1{if(j==-1||s[i]==t[j]){i++;j++;}else{j=next[j];}}deletenext; 阅读全文
posted @ 2013-05-14 21:26 herizai 阅读(206) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<sstream>using namespace std;int main(){ int n; char *months[12]= { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October&quo 阅读全文
posted @ 2013-05-14 21:17 herizai 阅读(123) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int main(){ char a[50],b[50]; int i; for(i=0;i<50;i++) cin>>a[i]; int cnt_index=0,cnt_int=0; //cnt_int 用于存放字符串中的数字. //cnt_index 作为字符串b的下标. for(i=0;a[i]!='\0';++i) //当a数组元素不为结束符时.遍历字符串a.//遍历的一种方法 { if(a[i]>='0'&& a[i]< 阅读全文
posted @ 2013-05-14 21:05 herizai 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 写出如下程序运行结果:#include<stdio.h>#include<string.h>intmain(){inta[2000];char*p=(char*)a;for(inti=0;i<2000;i++)a[i]=-1-i;printf("%d\n",strlen(p));return0;}请不要运行,先用草稿纸算算,能算出来不? 此乃网速科技2011校园招聘笔试题第一题,本人心里素质很不错,不过看到此题当时就懵了,哪有人这么写代码的,所以当时也没有做出来,后来运行以后也没有搞懂,刚刚吃饭,突然就明白了,特此记录、分享之。废话不多说,运行 阅读全文
posted @ 2013-05-14 20:13 herizai 阅读(149) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>using namespace std;void change(int **pointer,int n);//声明int main(){ int n,**p2; cout<<"请输入整数的个数n="; cin>>n; int *a=new int(n);//动态分配 cout<<"请输入:"; for(int i=0;i<n;++i) cin>>a[i];//存储 p2=&a; change(p2,n);//调用 cout<<&quo 阅读全文
posted @ 2013-05-14 20:12 herizai 阅读(183) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>structLIST{inta;LIST*back;};intmain(){intn;scanf("%d",&n);LIST*list=newLIST[n];//显示开辟了n个LIST结点for(inti=0;i<n;i++){list[i].a=i+1;//这是为第i个(从0数)LIST结点的数据域a赋值if(i!=n-1)//出于这个判断是为了形成一个环形链表,在i不等于n-1(也就是不是最后一个)的时候list[i].back=&list[i+1];//都是把list数组中的后一个元素(这里指的是L 阅读全文
posted @ 2013-05-14 19:16 herizai 阅读(164) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<sstream>using namespace std;int main(){ void compare(string *a); string a[3]; cout<<"请输入需比较的三个字符串:"; for(int i=0;i<3;++i) cin>>a[i]; compare(a); cout<<"从小到大排序为:"; for(i=0;i<3;++i) cout<<a[i]<<" " 阅读全文
posted @ 2013-05-14 18:35 herizai 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 裘宗燕:C/C++语言中的表达式求值经常可以在一些讨论组里看到下面的提问:“谁知道下面C语句给n赋什么值?”m=1;n=m+++m++;最近有位不相识的朋友发email给我,问为什么在某个C++系统里,下面表达式打印出两个4,而不是4和5:a=4;cout<<a++<<a;C++不是规定<<操作左结合吗?是C++书上写错了,还是这个系统的实现有问题?要弄清这些,需要理解的一个问题是:如果程序里某处修改了一个变量(通过赋值、增量/减量操作等),什么时候从该变量能够取到新值?有人可能说,“这算什么问题!我修改了变量,再从这个变量取值,取到的当然是修改后的值!”其 阅读全文
posted @ 2013-05-13 22:18 herizai 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 输入一个字符串,内有数字和非数字字符,如A123 456×17960? 302ta309*dal201n320将其中连续的数字作为一个整数,并输出这些数. 有什么简单的方法? 急!!! #include <stdio.h> main() { char str[50], *pstr; int i,j,k,m,e10,digit,ndigit,a[10],*pa; printf("Input a string: \n"); gets(str); printf("\n"); pstr=&str[0]; /* 字符指针pstr置于数 阅读全文
posted @ 2013-05-13 17:38 herizai 阅读(550) 评论(0) 推荐(0) 编辑
摘要: 其实两个都是C++文件流的分支,在C++有一个stream这个类,所有的I/O都以这个“流”类为基础的,也就是他的子类。首先来说fstream吧!在fstream类中,有一个成员函数open(),就是用来打开文件的,其原型是: void open(const char* filename,int mode,int access); 参数: filename: 要打开的文件名 mode: 要打开文件的方式 access: 打开文件的属性 打开文件的方式在类ios(是所有流式I/O类的基类)中定义,常用的值如下: ios::app: 以追加的方式打开文件 ios::... 阅读全文
posted @ 2013-05-13 13:50 herizai 阅读(745) 评论(0) 推荐(0) 编辑
摘要: <sstream>库是最近才被列入C++标准的。(不要把<sstream>与标准发布前被删掉的<strstream>弄混了。)因此,老一点的编译器,如GCC2.95,并不支持它。如果你恰好正在使用这样的编译器而又想使用<sstream>的话,就要先对它进行升级更新。<sstream>库定义了三种类:istringstream、ostringstream和stringstream,分别用来进行流的输入、输出和输入输出操作。另外,每个类都有一个对应的宽字符集版本。简单起见,我主要以stringstream为中心,因为每个转换都要涉及到输入 阅读全文
posted @ 2013-05-13 13:49 herizai 阅读(1240) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<sstream>using namespace std;int main(){ string a; cout<<"请输入字符串:"; cin>>a; const string& b=a; cout<<"字符串的长度为:"<<b.length(); cout<<endl; return 1;} 阅读全文
posted @ 2013-05-13 13:28 herizai 阅读(171) 评论(0) 推荐(0) 编辑
摘要: /*创建一个长度为5行4列的二维整型数组,通过初始化,为数组中的前两列的10个元素赋初值,然后通过键盘输入,使后两列的10个元素获得值,将所有元素值乘以3后保存在数组中。输出数组时,按行序优先输出,再按列序优先输出(输出的第一行是数组中的第一列……,其实输出的就是“转置”),再将数组“倒”着输出(即最后一行最后一列的最先输出,第0行第0列的最后输出),再输出数组中的所有偶数,以及行列下标之和为3的倍数的元素值。*//***程序的版权和版本声明部分*Copyright(c)2012,烟台大学计算机学院学生*Allrightsreserved.*文件名称:array.cpp*作者:徐本锡*完成日期 阅读全文
posted @ 2013-05-12 02:21 herizai 阅读(257) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 下一页