有以下程序:
#include <iostream>
#include <fstream>
using namespace std;
int main()
ofstream ofile("D:\\test.txt");
if(!ofile)
cout<<"test.txt can’t open"<<end1;
return 0;
ofile<<"This book is C++"<<" "<<12345<<end1;
ofile.close();
ifstream ifile("D:\\test.txt");
if ( ! ifile)
cout<<"test.txt can’t open"<<end1;
return 0;
char str[80];
ifile>>str;
ifile.close();
cout<<str<<end1;
return 1;
程序执行后的输出结果是 【15】 。
参考答案:This
解析: 本题考核文件的I/O操作。程序中的初始化值不能被修改,所以程序最后输出n=10。另外程序中定义了ofstream类的对象ofile和ifstream类的对象 ifile,然后利用对象ofile在文件test.txt中写入“This book is C++12345”。最后利用对象ifile打开文件,将其中的数据输入到变量str中,由于读时遇到空F时就终止,所以str中存放的字符串为“This”。