//例7.12 将 “a"至”z"的26个英文字母写入文件,而后从该文件中读取并显示出来。
#include<iostream>
#include<fstream>
using namespace std;
int test_write(){
ofstream outf("f3.txt",ios::binary);
if(!outf){
cout<<"Cannot open output file\n";
exit(1);
}
char ch = 'a';
for(int i=0;i<26;i++){
outf.put(ch);
ch++;
}
outf.close();
return 0;
}
int test_read(){
ifstream inf("f3.txt",ios::binary);
if(!inf){
cout<<"Cannot open input file\n,";
exit(1);
}
char ch;
while(inf.get(ch))
cout<<ch;
inf.close();
return 0;
}
int main(){
cout<<"例7.12 将 \"a\"至\"z\"的26个英文字母写入文件,而后从该文件中读取并显示出来。"<<endl;
cout<<"start"<<endl;
test_write();
test_read();
cout<<endl<<"end"<<endl;
return 0;
}
例7.12 将 a 至 z的26个英文字母写入文件,而后从该文件中读取并显示出来。
最新推荐文章于 2022-09-27 22:32:36 发布