m0_65185517 2022-04-25 14:29 采纳率: 66.7%
浏览 42
已结题

C++问题,需要括号内的内容

//例7.12 将'a'至'z' 的26个英文字母写入文本文件,而后从该文件中读出并显示出来。
#include
#include
#include
using namespace std;
int main()
{ (1) outf("f3.txt", ios::out );
//定义输出文件流对象outf,输出方式打开文本文件f3.txt
if (!outf) //如果文件打开失败,outf返回0值
{ cout<<"Cannot open output file\n,"; exit(1); }

char ch='a';
for(int i=0;i<26;i++)//将'a'至'z'的26个英文字母写入文件
{ (2)
ch++;
}
(3) //关闭文件

ifstream (4) ( (5) , (6) );
//定义输入文件流对象inf,打开输入文本文件f3.txt
if (!inf ) //如果文件打开失败
{ cout<<"Cannot open input file\n,"; exit(1);}
while( (7) ) //流类的函数eof()返回值为零表示文件没结束
{ (8) //从文件中读出一个字符
cout<<ch; }
//while( inf.get(ch) )//从文件中读出字符,读取成功则get函数返回非0值,如失败(遇文件结束符EOF)则函数返回0值
// cout<<ch;
inf.close(); //关闭文件

return 0;
}

  • 写回答

1条回答 默认 最新

  • 浪客 2022-04-25 14:46
    关注

    题目中就有答案
    1 ofstream
    2 outf << ch;
    3 outf.close();
    4 inf
    5 "f3.txt"
    6 ios::in
    7 !inf.eof()
    8 inf.get(ch)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 9月12日
  • 已采纳回答 9月4日
  • 创建了问题 4月25日