执行语句序列 ofstream outfile(”DATA.DAT"); if(…)cout<<"OK";elsec out<<"FAIL"; 后,如果文件打开成功显示“OK”,否则就显示“FAIL”。由此可知,上面if语句的…处的表达式应是
A.outfile.fail()或 outfile
B.outfile.good()或 !outfile
C.outfile.good()或 outfile
D.outfile.fail()或 !outfile
第1题:
写出下列程序的运行结果【 】。
include <iostream.h>.
include <fstream.h>
include <stdlib.h>
void main()
{
fstream outfile, infile;
outfile.open("data.clat", ios:: out);
if(!outfile)
{
cout<<"Can't open the file."<<end1;
abort();
}
outfile<<" 1234567890"<<end1;
outfile<<"aaaaaaaaa"<<end1;
outfile<<"**********"<<end1;
outfile.close();
infile.open("data. dat ", ios:: in);
if(!infile)
{
cout<<"Can't open the file."<<end1;
abort();
}
char line[80];
int I=0;
while(!infile. eof())
{
I++;
infile.getline(line, sizeof(line));
cout<<I<<":"<<line<<end1;
}
infile.close();
}
第2题:
执行语句序列 ofstream outfile("data.dat"); if(...)cout<<"ok";else cout<<"fail"; 后,如果文件打开成功,显示“ok”,否则显示“fail”。由此可知,上面if语句的“...”处的表达式是( )。
A.outfile.fail()或outffle
B.outfile.good()或!outfile
C.outfile.good()或outfile
D.outfile.fail()或!outfile
第3题:
执行下列语句序列后, ofstream outfile("DATA.DATA") if(…)cout<<"OK";else cout<<"FAIL";如果文件打开成功显示OK,否则就显示FAIL。由此可知,…处的表达式应是( )。
A.outfile.fail()或outfile
B.outfile.fail()或! outfile
C.outfile.good()或outfile
D.outfile.goodl()或! outfile
第4题:
执行语句序列 ofstream outfile ("DATA. DAT"); if(...)cout <<"OK";else cout <<"FAIL";后,如果文件打开成功,显示"OK",否则就显示"FAIL"。由此可知,上面if语句的...处的表达式应是______ 。
A.outfile.fail ()或outfile
B.outfile. good() 或outfile
C.outfile.good ()或!outfile
D.outfile.fail()或!outfile
第5题:
执行语句序列 ofstream outfite("data.dat"); if(...)cout<<"ok";else cout<<"fail"; 后,如果文件打开成功,显示 “ok”,否则显示“fail”。由此可知,上面if语句的“…”处的表达式是
A.outfile.fail()或outfile
B.outfile.good()或!outfile
C.outfile.good()或outfile
D.outfile.fail()或!outfile