摘要:#include #include voidmain() { charSourceName[81]; charDestinName[81]; cout>SourceName; cout>DestinName; try { CFilefileSource(SourceName,CFile::modeRead); ...
阅读全文
随笔分类 - C++
基础知识
摘要://读写2进制流文件 #include #include #include voidmain() { ofstreamf1("wr1.dat"); if(!f1) { cerr>x) cout<<x<<''; cout<<endl; f2.close(); }
阅读全文
摘要:c++中创建动态二维数组的程序代码 动态创建一维数组 int*arr;//itcanbeanyothertype(char,float) arr=newint[n];//nshouldbeintegervariable 动态创建二维数组 int**arr; intN,M; cin>>N>>M; arr=newint*...
阅读全文
摘要:#include #include #include voidmain() { srand((unsigned)time(NULL));//以系统时间作种子,就不会每次都产生一样的序列了 doubletemp=double(rand()%4000+3000)/10000.0;//调节精度 temp=temp<0.5?(temp-0.2):(...
阅读全文
摘要:全局变量的定义一直不知道怎么弄,困绕很久,终于在vckbase之阿荣的BLOG上找到答案了 http://blog.vckbase.com/arong/archive/2004/05/28/294.aspx 简述如下:工程中有xx.cpp,yy.cppxx.h,yy.h等,在xx.cpp里的函数外部分定义变量int test=5;为了在yy.cpp里使用刚刚定义的tes...
阅读全文
摘要:①对于一般常量,const在类型说明符的前面或者后面,都是一样的.eg: const int i=9; int const i=9; ②使用const修饰指针时,会由于const位置不同而含义不同. eg: char * const p=str1;p为常量指针,p的指向不可以变,而*p可更新,即语句p=str2 非法,语句*p="C"正确. const char * p=str1;p...
阅读全文
摘要:C允两者不一致,而C++则不允许. //...... void *f; int i=1,*p; f=&i; p=(int*)f; f=p; cout<<"p is "<<p<<*p; cout<<"f is "<<f<<*f; // void...
阅读全文
摘要:1.new 用法:指向对应类型的指针=new 类型描述符 a. 一个机器字长 int *p; p=new int; b. 一个机器字长,并赋值 int *p; p=new int(20); c. 多个字长,按数组或指针引用 int *p; p=new int [20]; 2.delete 用法:delete 指针名 指针是数组...
阅读全文
摘要:1#include 2#include 3inttemp,m[30][30]={0,}; 4voidHelix(intmin,intmax) 5{ 6for(inti=min;i>N; 22if(N30) 23break; 24max=N-1; 25temp=1...
阅读全文