对于下面的程序 ifstream fin(c:\test.txt); if(fin) cout<<"ok"; else cout<<"wrong"; 对于if语句中的内容可以换为
A.fin.fail( ):
B.fin.bad( );
C.fin.good( );
D.fin.eof( );
第1题:
( 16 )要建立文件流并打开当前目录下的文件 file.dat 用于输入,下列语句中错误的是
A ) ifstream fin=ifstream.open ( "file.dat" ) ;
B ) ifstream*fir.=new ifstream ( "file.dat" ) ;
C ) ifstream fin; fin.open ( "file.dat" ) ;
D ) ifstream *fin=new ifstream ( ) ; fin 一 >open ( "file.dat" ) ;
第2题:
#include<iostream.h>int main(){ int a; cout<<"请输入一个大于0的数:\n"; cin>>a; if (judge(a)==0){ cout<<"\n是偶数。"; }else{ cout<<"\n是奇数。"; }}int judge(int s){ if(s%2==0) { return 0; }else{ return 1; }}上面的程序哪里错了啊?为啥不能编译成功?
第3题:
若磁盘上已存在某个文本文件,其全路径文件名为 d:\ncre\test.txt ,下列语句中不 能打开该文件的是
A . ifstream file("d:\ncre\test.txt") ;
B . ifstream file("d:\ncre\test.txt");
C . ifstream file; file.open("d:\ncre\test.txt");
D . ifstream* pFile=new ifstream("d:\ncre\test.txt");
第4题:
若语句: cout<<seffill('>')<<setw(5)<<3141512<<sctw(5)<<"OK!"; 是程序中第1个输出语句,则输出结果是( )。
A.3141512>>OK!
B.31415120K!>>
C.314150K!>>
D.31415>>OK!
第5题:
有如下程序:#include <iostream>#include <iomanip>using namespace std;int main(){cout.fill('*');cout<<left<<setw(4)<<123<< "OK"<<end1;return 0;}执行这个程序的输出结果是( )。
A.123*OK
B.123*OK**
C.*123OK
D.*123**OK
第6题:
下面的程序的结果是
main( )
{int x=3,y=0, z=0;
if(x=y+z)cout<<"* * * *";
else cout<<"####";
}
A.有语法错误不能通过编译
B.输出****
C.可以通过编译,但是不能通过连接,因而不能运行
D.输出####
第7题:
下列程序从保存整数的文本文件”c:Sample.dat”中依次取出每个数据并显示出来,同时统计并显示出所有数据的个数。程序划线处的表达式为______。
include<stream.h>
include<stdlib.h>
void main( )
{
ifstream fin("c:Sample.dat",los::nocreate);
if(! fin)
{
cout<<"文件无法打开!"<<endl;
exit(1);
}
int x,i=0;
while(______)
{
cout<<x<<"";
i++;
}
fin.close( );
cout<<endl<<"文件中所有整数个数:"<<i<<endl;
}
第8题:
若语句: cout<<setfill('>')<<setw(5)<<3141512<<setw(5)<<"OK!"; 是程序中第一个输出语句,则输出结果是
A.3141512>>OK!
B.31415120K!>>
C.414150K!>>
D.31415>>OK!
第9题:
对于下面的程序: ifstream fin(c:\test.txt) ; if(fin) cout < < "ok"; else cout < < "wrong"; if语句中的内容可以换为
A.fin. fail( ) ;
B.fin. bad( ) ;
C.fin. good( ) ;
D.fin. eof( ) ;
第10题:
以下程序的输出结果是( )。 #include<iostream.h> main() { int m=5; if(m++>5) cout<<m; else cout<<m--; }
A.7
B.6
C.5
D.4