随笔分类 - other
摘要:1 //自己写的! 2 3 #include 4 5 using namespace std; 6 7 8 typedef struct _DATA_ 9 { 10 11 char szName[20]; 12 int iAge; 13 }Data,*pData; 14 15 typedef struct _NODE_ 16 { 17 Data DataTemp; 18 _NODE_* pNext; 19 }Node,*pNode; 20 21 22 class CList 23 { 24 public: 25 CLi...
        阅读全文
                
摘要:通常文件打开后,读写位置按先后顺序.但有时你想变动读写位置,例如重新从某处起,再读一次.int fseek(FILE *stream, long offset, int fromwhere);fseek 用于二进制方式打开的文件,移动文件读写指针位置.fseek(in,-1L,1); -- 文件流in, 零点为当前指针位置,SEEK_CUR 就是 1, -1L -- 文件指针回退1个字节int fseek( FILE *stream, long offset, int origin ); 第一个参数stream为文件指针 第二个参数offset为偏移量,整数表示正向偏移,负数表示负向...
        阅读全文
                
摘要:1 #include 2 3 4 using namespace std; 5 6 typedef struct _NODE_ 7 { 8 int a; 9 _NODE_* pNext; 10 11 }Node,*pNode; 12 13 14 class CList 15 { 16 17 private: 18 pNode m_pHead; 19 pNode m_pTail; 20 int iNodeCount; 21 22 public: 23 CList() 24 { 25 m_p...
        阅读全文
                
摘要://1.1 输入两个数A,B,算出结果#includeint main(){ int a, b; cout>a>>b; cout#includeint main(){ double a,b; cout>a>>b; cout.precision(4); coutint main(){ int sum, hour, min, second; cout>sum; if(sumint main(){ int time; int H,M,S; there: cout>time; if(time864...
        阅读全文
                
摘要:1 //Lee. 控制台 贪吃蛇 2 //测试版本1.1 3 //解决几个问题,1.为什么Map[79][24] 地图的横坐标都要用X * 2的形式,, 4 // 而纵坐标的1却表示两个字节。 5 /* (即横坐标1表示一个宽度,但是纵坐标的1表示两个宽度) 6 因为是字符游戏,地图并不是那么重要,只要有个标记能让玩家看清边界就行了. 但是 7 ...
        阅读全文
                
摘要:如果是在Windows上, 实现背景音乐, 我所了解的有以下几种方式:1. 用PlaySound函数作异步播放. 优点:用起来相当方便 缺点:只能播wav格式的文件而且wav文件不能太大, 否则会占很多内存;我自己在电脑上的一个例子 1 #include<stdio.h> 2 #include<windows.h> 3 #include <mmsystem.h> 4 #pragma comment(lib, "winmm.lib ") 5 #include<stdlib.h> 6 int main() 7 { 8 PlaySo
        阅读全文
                
摘要:今天早上早起起来写代码主要是完善了 暂停和重新开始游戏,以及退出功能。对界面进行了完善。然后是使用了PCC32库文件。调用了函数setTextColor(),实现了彩色功能。界面也更人性化了点,还有待改进。下午继续,! 1 //Lee. 控制台 贪吃蛇 2 //测试版本1.0 3 //几点疑问,1.为什么Map[79][24] 地图的横坐标都要用X * 2的形式,, 4 // 而纵坐标 的1却表示两个字节。 5 /*3.3.1 画地图 (即横坐标1表示一个宽度,但是纵坐标的1表示两个宽度) ...
        阅读全文
                
摘要:1 // temp1.cpp : Defines the entry point for the console application. 2 // 3 4 //#include <stdafx.h> 5 #include <windows.h> 6 #include <conio.h> 7 #include <stdlib.h> 8 #include<stdio.h> 9 int main(int argc, char* argv[])10 {11 SetConsoleTitle("Hello World!");
        阅读全文
                
摘要:1 用于控制台窗口操作的API函数如下: 2 3 GetConsoleScreenBufferInfo 获取控制台窗口信息 4 GetConsoleTitle 获取控制台窗口标题 5 ScrollConsoleScreenBuffer 在缓冲区中移动数据块 6 SetConsoleScreenBufferSize 更改指定缓冲区大小 7 SetConsoleTitle 设置控制台窗口标题 8 SetConsoleWindowInfo 设置控制台窗口信息 9 10 此外,还有窗口字体、显示模式等控制函数,这里不再细说。下列举一个示例,程序如下: 11 12 #in...
        阅读全文
                
摘要:显示模仿别人,然后是自己做了点修改,包括游戏结束和界面上。。这个终于写出来了。早上的时间没有白费。 1 //Lee. 控制台 贪吃蛇 2 //测试版本 3 4 5 #include<stdio.h> 6 #include<windows.h> 7 #include<conio.h> 8 #include<time.h> 9 #include<stdlib.h> 10 11 #define UP 72 //定义上下左右常量 12 #define DOWN 80 13 #define LEFT 75 14 #define RIGHT 77
        阅读全文
                
摘要:1 typedef struct _COORD { // coord. 2 SHORT X; // horizontal coordinate 3 SHORT Y; // vertical coordinate 4 } COORD; 5 6 WINDOWS API中定义的一个结构7 8 表示一个字符在控制台屏幕上的坐标,坐上角(0,0) 1 SetConsoleCursorPosition是API中定位光标位置的函数。 2 #include<stdio.h> 3 #include<windows.h> 4 int main() 5 { 6 HANDLE hO...
        阅读全文
                
摘要:自己想改一改,结果发现不能这样,,写出来是错误的,双字符不能这样弄。。。 1 //简单的控制台 贪吃蛇 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<conio.h> 5 #include<time.h> 6 #include<string.h> 7 8 #define H 30 9 #define L 30 10 11 int key; //用来存放按键 12 int length = 1, over = 0; //蛇的长度, 结束 13 int dx[4]={0,0,-1,
        阅读全文
                
摘要:这是第一次做小游戏,下面对别人写的一个非常简单的基本功能的贪吃蛇进行分析VC下可以运行。。先看下源代码,基本上注释我都加在里面了,同时保留了作者的版权。 1 //******************************************************* 2 //**************版权所有***2011.9.20***咸鱼************** 3 //******************************************************* 4 //*友情提示:如想速度快点,请改小_sleep(500)函数中参数***** 5 ...
        阅读全文
                
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=10; 6 7 void BubbleSort(int arr[], int n) 8 { 9 int i, j, t;10 for(i=0;iarr[j+1])15 {16 t=arr[j+1];17 arr[j+1]=arr[j];18 arr[j]=t;19 }20 }21...
        阅读全文
                
摘要:1 #include 2 #include 3 #include 4 #define N 10 5 int main() 6 { 7 int a[N], i, j, temp, b; 8 srand(time(NULL)); 9 for(i=0;ia[j])20 temp=j;21 }22 if(i!=temp)23 {24 b=a[temp];25 a[temp]=a[i];26 a[i]=b;27 ...
        阅读全文
                
摘要:puts 和 printf 的用法一样,puts()函数的作用与语句“printf("%s\n",s);的作用相同。注意:puts在输出字符串后回车符。当puts遇到\0时,会输出一个\n,也就是换行。所以puts( "" )时,因为字符串本身长度为0,所以第一个字符就是\0,puts会输出一个\n,所以起到了换行的效果。也就是说, puts( "" )跟puts( "\0" )是等效的,也等效printf( "\n" )
        阅读全文
                
摘要:要求:了解多维数组的概念掌握二维数组的使用掌握用字符数组存放字符串的方法掌握字符串的输入及输出方法二维数组的定义 例:int a[2][3]; 定义一个二维数组 该数组有2行3列共6个元素 这6个元素都存放int型数据 存储时先存储第一行的3个元素,然后再存储第二行的3个元素 可将此二维数组看成是一个有2个元素(一维数组)的一维数组,每个元素又是一个有3个元素(int)的一维数组二维数组的初始化 ⑴ int i[3][4] //没初始化,值不确定 ⑵ int i[2][2]={1,2,3,4} //有4个元素,且都有确定的值,按存储顺序初始化 ⑶ int i[2][2]=...
        阅读全文
                
摘要:1。void *memset(void *s,int c,size_t n)总的作用:将已开辟内存空间 s 的首 n 个字节的值设为值 c。2。例子#includevoid main(){char *s="Golden Global View";clrscr();memset(s,'G',6);printf("%s",s);getchar();return 0;} 3。memset() 函数常用于内存空间初始化。如:char str[100];memset(str,0,100);4。memset()的深刻内涵:用来对一段内存空间全部设置为
        阅读全文
                
摘要:学C++的时候,这几个输入函数弄的有点迷糊;这里做个小结,为了自己复习,也希望对后来者能有所帮助,如果有差错的地方还请各位多多指教(本文所有程序均通过VC 6.0运行)转载请保留作者信息;1、cin1、cin.get()2、cin.getline()3、getline()4、gets()5、getchar()1、cin>>用法1:最基本,也是最常用的用法,输入一个数字:#include using namespace std;main (){int a,b;cin>>a>>b;coutusing namespace std;main (){char a[20
        阅读全文
                
摘要:1 C++ 字符串(string类)函数 2 首先明确 字符串是从第0位 开始存储的 3 即 string s="123"; s[0]==1; 4 5 string ss="0123456789"; 6 string ss2; 7 1.求长度 8 int len=ss.length(); //求字符串ss的长度返回值赋给len 9 (此时len==10)10 11 2.提取子串12 string ss2;13 ss2=ss.substr(pos);//返回从pos开始的(包括pos)的子串赋给ss2;14 (例 ss2=ss.substr(8);//此时
        阅读全文
                
                    
                
浙公网安备 33010602011771号