- //文件名:CHAPTER2-12.cpp
- #include<fstream.h>
- #include<iostream.h>
- #include<process.h>
- void main()
- {
- int i=30;
- float f=12.34;
- char c;
- fstream fl("sf",ios::out|ios::in);
- if(!fl) {cerr<<"The File Open Error."<<endl; exit(255);}
- fl<<"I="<<i<<" ;F="<<f<<endl;
- fl.seekp(ios::beg); //指针回文件首
- fl>>c>>c; //字符串"I="读出后不使用
- fl>>++i; //i加1后从盘上读出i仍为30
- cout<<i<<endl;
- }