空间数据库第七章数据库原理和VC的文件系统_第1页
空间数据库第七章数据库原理和VC的文件系统_第2页
空间数据库第七章数据库原理和VC的文件系统_第3页
空间数据库第七章数据库原理和VC的文件系统_第4页
空间数据库第七章数据库原理和VC的文件系统_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第七章数据库原理 和VC+的文件系统 武汉理工大学资源与环境工程学院 空间数据库空间数据库 School of Resource float f; char *ch; s1; 不能用输出函数来输出以上结构变量: printf(“%sample”,s1); 空间数据库空间数据库 School of Resource class istream: virtual public ios; class ostream: virtual public ios; class iostream: public istream,public ostream; 又如: class istream_withass

2、ign: public istream; class ostream_withassign: public ostream; 空间数据库空间数据库 School of Resource cout“Type a line terminated by t” endl; cin.getline(line,100,t); cout读入字符串时,在遇到第一个空格读入字符串时,在遇到第一个空格 字符后输入将停止。字符后输入将停止。 空间数据库空间数据库 School of Resource outfile.open(f1.txt, ios:out); 空间数据库空间数据库 School of Resour

3、ce 写 ofstream ostrm; ostrm.open(f1.txt); 或 写 ifstream istrm(f2.txt); 读 ifstream istrm; istrm.open(f2.txt); 或 读 空间数据库空间数据库 School of Resource 空间数据库空间数据库 School of Resource ostrm.open(f1.dat); ostrm 12 endl; ostrm 310.85 n d; cout n , d endl; istrm.close( ); Ans: 12,310.85 空间数据库空间数据库 School of Resourc

4、e void main( ) fstream outfile; outfile.open(f2.dat, ios:out); if(!outfile) cout f2.dat cant open.n; abort( ); outfile this is a program.n; outfile this is a program.n; outfile.close( ); 空间数据库空间数据库 School of Resource infile.open(f2.dat, ios:in); if(!infile) cout f2.dat cant open.n; abort( ); char s8

5、0; while(!infile.eof( ) / eof( ) 文件结束返回非 0 infile.getline(s,sizeof(s); / getline( )对 infile 读取一行 cout s endl; infile.close( ); 空间数据库空间数据库 School of Resource outfile.open(f3.dat, ios:out); if(!outfile) cout f3.dat cant open.n; abort( ); char str = this is a C+ program.; 空间数据库空间数据库 School of Resource

6、i = strlen(str); i+) outfile.put(stri); outfile.close( ); infile.open(f3.dat, ios:in); if(!infile) cout f3.dat cant open.n; abort( ); char ch; while(infile.get(ch) cout ch; cout endl; infile.close( ); Ans: this is a C+ program. 空间数据库空间数据库 School of Resource infile.open(f2.dat, ios:in); if(!infile) c

7、out f2.dat cant open.n; abort( ); outfile.open(f4.dat, ios:out); if(!outfile) cout f4.dat cant open.n; abort( ); char ch; while(infile.get(ch) outfile.put(ch); infile.close( ); outfile.close( ); 空间数据库空间数据库 School of Resource double height; unsigned short age; ; struct person people4 = Wang, 1.65, 25

8、, Zhang, 1.72, 24, Li, 1.89, 21, Hung, 1.70, 22; void main( ) fstream infile, outfile; outfile.open(f5.dat, ios:out | ios:binary); if(!outfile) cout f5.dat cant open.n; abort( ); 空间数据库空间数据库 School of Resource i4; i+) outfile.write(char *) outfile.close( ); infile.open(f5,dat, ios:in | ios:binary); i

9、f(!infile) cout f5.datcant open.n; abort( ); for(i=0; i4; i+) infile.read(char *) cout t peoplei.height t peoplei.age endl; infile.close( ); 空间数据库空间数据库 School of Resource 和都是long型量,并以字节数 为单位 有如下的含义: cur = 1 相对于当前读指针所指定的位置 beg = 0 相对于流的开始位置 end = 2 相对于流的结尾处 空间数据库空间数据库 School of Resource

10、以当前位置为基准向前(流的开始位置方向)移动以当前位置为基准向前(流的开始位置方向)移动100100 各字节处各字节处 input.seekg(100, ios:beg); 从流开始的位置后移从流开始的位置后移100100个字节处个字节处 input.seekg(-100, ios:end); 相对于流结尾处前移相对于流结尾处前移100100个字节处个字节处 tellg ( )函数返回一个函数返回一个long型值,表示当前读指针的位型值,表示当前读指针的位 置相距流开始位置的字节数置相距流开始位置的字节数 seekg( )seekg( )函数设置了读指针位置,下一次的提取操作就函数设置了读指针

11、位置,下一次的提取操作就 从当前位置开始,根据提取的数据的字节数从当前位置开始,根据提取的数据的字节数n n,提取操,提取操 作完成后,读指针将被后移作完成后,读指针将被后移n n个字节位置,再次提取操个字节位置,再次提取操 作将从新的当前位置开始作将从新的当前位置开始 空间数据库空间数据库 School of Resource 和 seekg、tellg 雷同 空间数据库空间数据库 School of Resource if(!file) cout f7.dat cant open.n; abort( ); 空间数据库空间数据库 School of Resource i15; i+) / 每

12、个 int,占4 个 byte file.write(char *) streampos pos = file.tellp( ); cout Current byte number: pos endl; for(i=15;i45;i+) file.write(char *) file.seekg(pos); / 输入文件,读 file.read(char *) cout The data stored is i endl; file.seekp(0, ios : beg); / 输出文件,写 for(i=80; i 100; i+) file.write(char *) file.seekg(

13、pos); file.read(char *) cout The data stored is i endl; cout Current byte number: file.tellp( ) endl; 空间数据库空间数据库 School of Resource long number; double totalscord; stu5=Ma,97001,85.72, Li,97002,92.62, Hu,97003,85.25,Yan,97004,90.84,Lu,97005, 80.92; fstream file1; student one; file1.open(f7.dat, ios:out | ios:in | ios:binary); 空间数据库空间数据库 School of Resource abort( ); for(int i=0; i 5; i+) file1.write(char *) file1.seekp(sizeof(student)*4); file1.read(char *) cout t one.number t one.totalscord endl; file1.seekp(sizeof(student)*1); file1.read(char *) cout one.nam

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论