09 2012 档案

摘要:#include <sys/types.h>#include <sys/wait.h>#include <unistd.h>#include <stdio.h>int main(){ pid_t pid; char *m; int n; pid=fork(); if(pid==0) { m="this is child"; n=5; } else { m="this is fath... 阅读全文
posted @ 2012-09-28 16:23 Dsp Tian 阅读(2122) 评论(0) 推荐(0) 编辑
摘要:#在宏中表示把参数变为字符串##在宏中表示连接两个参数#include <iostream>using namespace std;#define str(s) #s#define cons(a,b) a##bint main() { cout<<str(asfsd)<<endl; cout<<cons(1,2)<<endl; system("pause"); return 0; } 阅读全文
posted @ 2012-09-21 10:54 Dsp Tian 阅读(636) 评论(0) 推荐(0) 编辑
摘要:// overload_date.cpp// compile with: /EHsc#include <iostream>using namespace std;class Date{ int mo, da, yr;public: Date(int m, int d, int y) { mo = m; da = d; yr = y; } friend ostream& operator<<(ostream& os, const Date& dt);};ostream& operator<<(ostream& os, c 阅读全文
posted @ 2012-09-19 16:24 Dsp Tian 阅读(472) 评论(0) 推荐(0) 编辑
摘要:extern "C" {#include "lua.h" #include "lualib.h" #include "lauxlib.h"}; /* Lua解释器指针 */lua_State* L;int main ( int argc, char *argv[] ){ /* 初始化Lua */ L = lua_open(); /* 载入Lua基本库 */ luaL_openlibs(L); /* 运行脚本 */ luaL_dofile(L, "test.lua"); /* 清除Lu... 阅读全文
posted @ 2012-09-18 20:13 Dsp Tian 阅读(618) 评论(0) 推荐(0) 编辑
摘要:解决方案:sudo rm /var/lib/apt/lists/* -vfsudo apt-get update 阅读全文
posted @ 2012-09-15 09:20 Dsp Tian 阅读(393) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;class test{public: test(int a,...); ~test(); void setdata(); void showdata(); int **data; int *N; //存储每个参量的值 int n; //统计参量的个数};test::test(int a,...){ int *p=&a; n=0; while (*p!=0) { n++; p++; } data=new int... 阅读全文
posted @ 2012-09-11 14:35 Dsp Tian 阅读(418) 评论(0) 推荐(0) 编辑
摘要:/*va_list vl; //定义一个指向参数列表的变量(一个...指针)va_start(vl,first_param); //把指向参数列表的变量初始化va_arg(vl,mode); //获取下一个参数,参数类型由第二个参数指定,第二个参数用于在va_arg内部进行尺寸计算,以便找到下一个参数va_end(vl); //结束*/#include <iostream>#include <cstdarg> //头文件包含:C++ <cstdarg>; C <stdarg.h>using namespace std;void variable( 阅读全文
posted @ 2012-09-11 09:49 Dsp Tian 阅读(484) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;int main(){ double **a; a=new double *[3]; //初始一个三行二列的矩阵 for (int i=0;i<3;i++) { a[i]=new double[2]; } a[0][0]=1; a[0][1]=2; a[1][0]=4; a[1][1]=5; a[2][0]=7; a[2][1]=8; for (int i=0;i<3;i++) { ... 阅读全文
posted @ 2012-09-10 20:26 Dsp Tian 阅读(9088) 评论(0) 推荐(0) 编辑
摘要:新用这个,不太熟悉,最后那几步老忘,先把自己用的记在这里。 首先在github上注册一个账号。 下载git客户端,我windows下的是git-1.7.11-preview,搜一下网上很多。ubuntu内置了有git。 打开git bash。 输入 git config –global user.n 阅读全文
posted @ 2012-09-10 15:50 Dsp Tian 阅读(510) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h>#include <termios.h>int main(){ char s;// FILE *in;// FILE *out; struct termios initial_settings,new_settings;// in=fopen("/dev/tty","r");// out=fopen("/dev/tty","w"); tcgetattr(fileno(stdin),&initial_settings);//保存原来的设置 new_s 阅读全文
posted @ 2012-09-09 21:20 Dsp Tian 阅读(800) 评论(0) 推荐(0) 编辑
摘要:#include <sys/utsname.h>#include <unistd.h>#include <stdio.h>int main(){ char computer[256]; struct utsname uts; if(gethostname(computer,256)!=0 || uname(&uts)<0) { exit(1); } printf("Computer host name is %s\n",computer); printf("Syste... 阅读全文
posted @ 2012-09-09 16:42 Dsp Tian 阅读(677) 评论(0) 推荐(0) 编辑
摘要:#include <sys/types.h>#include <stdio.h>#include <pwd.h>#include <unistd.h>int main(){ uid_t uid; gid_t gid; struct passwd *pw; uid =getuid(); gid=getgid(); printf("User is %s\n",getlogin()); printf("User IDs:uid=%d,gid=%d\n",uid,gid); pw=getpw... 阅读全文
posted @ 2012-09-09 16:26 Dsp Tian 阅读(481) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h>int main(){ char tmpname[L_tmpnam]; char *filename; FILE *tmpfp; filename=tmpnam(tmpname); printf("tmp file is : %s\n",filename); tmpfp=tmpfile(); if(tmpfp) printf("open a tmp file ok\n"); else ... 阅读全文
posted @ 2012-09-09 14:41 Dsp Tian 阅读(563) 评论(0) 推荐(0) 编辑
摘要:#include <time.h>#include <stdio.h>int main(){ time_t the_time; (void)time(&the_time); printf("The date is: %s",ctime(&the_time)); return 0;}函数原型:#include <time.h>char *ctime(const time_t *timeval);注:上一篇获得的时间是标准格林威治时间。 阅读全文
posted @ 2012-09-09 14:21 Dsp Tian 阅读(476) 评论(0) 推荐(0) 编辑
摘要:#include <time.h>#include <stdio.h>int main(){ struct tm *tm_ptr; time_t the_time; (void) time(&the_time); tm_ptr=gmtime(&the_time); printf("Raw time is %ld\n",the_time); printf("gmtime gives:\n"); printf("date: %02d/%02d/%02d\n", tm_ptr->tm_year, 阅读全文
posted @ 2012-09-09 14:09 Dsp Tian 阅读(465) 评论(0) 推荐(0) 编辑
摘要:#include <time.h>#include <stdio.h>#include <unistd.h>int main(){ int i; time_t the_time; for(i=1;i<=5;i++) { the_time=time((time_t*)0); printf("the time is %ld\n",the_time); sleep(2); } exit(0);}时间是从1970年1月1日开始的。函数原型... 阅读全文
posted @ 2012-09-09 14:01 Dsp Tian 阅读(488) 评论(0) 推荐(0) 编辑
摘要:#include <stdlib.h>#include <stdio.h>#include <string.h>int main(int argc,char **argv){ char *var,*value; if(argc==1||argc>3) { exit(1); } var=argv[1]; value=getenv(var); if(value) printf("Variable %s has value %s\n",var,... 阅读全文
posted @ 2012-09-08 10:46 Dsp Tian 阅读(612) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h>#include <unistd.h>int main(int argc,char **argv){ int opt; while((opt=getopt(argc,argv,"if:lr"))!=-1) { switch(opt) { case 'i': case 'l': case 'r': ... 阅读全文
posted @ 2012-09-08 10:22 Dsp Tian 阅读(470) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h>#include <stdlib.h>extern char **environ;int main(){ char **env=environ; while(*env) { printf("%s\n",*env); env++; } exit(0);}主要是environ变量,定义如下#include <stdlib>extern char **environ; 阅读全文
posted @ 2012-09-08 09:59 Dsp Tian 阅读(477) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h>#include <stdlib.h>int main(){ int c; FILE *in,*out; in=fopen("file.in","r"); out=fopen("file.out","w"); while((c=fgetc(in))!=EOF) fputc(c,out); exit(0);} 阅读全文
posted @ 2012-09-06 14:13 Dsp Tian 阅读(2017) 评论(0) 推荐(0) 编辑
摘要:#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <stdlib.h>int main(){ char block[1024]; int in,out; int nread; in=open("file.in",O_RDONLY); out=open("file.out",O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR); while ((nread= 阅读全文
posted @ 2012-09-06 14:12 Dsp Tian 阅读(721) 评论(0) 推荐(0) 编辑
摘要:#include <unistd.h>#include <stdlib.h>int main(){ char buffer[128]; int nread; nread=read(0,buffer,128); if(nread==-1) write(2,"A read error has occurred\n",26); if((write(1,buffer,nread))!=nread) write(2,"A write error has occurred\n"... 阅读全文
posted @ 2012-09-02 17:43 Dsp Tian 阅读(642) 评论(0) 推荐(0) 编辑
摘要:#include <unistd.h>#include <stdlib.h>int main(){ if((write(1,"here is some data\n",18))!=18) write(2,"write error\n",12); exit(0);}原型:#include <unistd.h>size_t write(int fildes,const void *buf,size_t nbytes);write()的第一个参数:0标准输入,1标准输出,2标准错误 第二个参数:写入的数据 第三个参数:写入如 阅读全文
posted @ 2012-09-02 16:46 Dsp Tian 阅读(1543) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示