万能百科  > 所属分类  > 

以下程序执行后输出的结果是【】。 include include using namespace std; int

以下程序执行后输出的结果是【 】。

include<iostream>

include<fstream>

using namespace std;

int main(){

ofstream ofile("D:\\temp.txt");

if(!ofile){

cout<<"temp.txt cannot open"<<endl;

return 0;

}

ofile<<"This is a book" <<" " <<54321<<endl;

ofile.close();

ifstream ifile("D:\\temp.txt");

if(!ifile){

cout<<"temp.txt cannot open" <<endl;

return 0;

}

charstr[40];

ifile >> str;

ifile.close();

cout<<Str<<endl;

return 1;

}

正确答案:

ThisThis 解析:程序中利用对象ofile在文件temp.txt中写入“This is a book 54321”。然后利用对象 ifile打开文件,将其中的数据输入到变量str中,由于读时遇到空格就终止,所以str中存放的字符串为“This”。

词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。

标签