对于下面的程序 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题:
#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; }}上面的程序哪里错了啊?为啥不能编译成功?
第2题:
有如下程序:#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
第3题:
若语句: cout<<seffill('>')<<setw(5)<<3141512<<sctw(5)<<"OK!"; 是程序中第1个输出语句,则输出结果是( )。
A.3141512>>OK!
B.31415120K!>>
C.314150K!>>
D.31415>>OK!
第4题:
下面程序运行结果为( )。 main() { char c='a'; if('a'<c< ='z') cout<<"LOW"; else cout<<"UP"; }
A.LOW
B.UP
C.LOWUP
D.语句错误,编译不能通过
第5题:
执行语句序列 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
第6题:
要建立文件流并打开当前目录下的文件file.dat用于输入,下列语句中错误的是
A.ifstream fin=ifstream.open(”file.dat”);
B.ifstream*fin=new ifstream(”file.dat”);
C.ifstream fin;fin.open(”file.dat”);
D.ifstream*fin=new ifstream();fin->open(”file.dat”);
第7题:
阅读下面的程序: #include<iostream.h> void main() { int x; cin>>x; if(x++>5) cout<<x<<endl; else cout<<x——<<endl; } 如果两次执行上述程序,且键盘输入分别为4和6,则输出结果分别是( )。
A.4,6
B.3,6
C.4,7
D.5,7
第8题:
有如下程序: #include <iostream> #include <iomanip> using namespace std; int main() { cout.fill('*'); cout << left << setw(4) << 123 << "OK" << endl; return 0; }
A.123*OK
B.123*OK**
C.*123OK
D.*123**OK
第9题:
执行下列语句序列后, 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
第10题:
当需要打开A盘上的abc.txt 文件用于输入时,则定义文件流对象的语句为______ 。
A.fstream fin(“A: abc.txt”);
B.ofstream fin (“A: abc.txt”);
C.ifstream fin(“A: abc.txt”,ios:: app);
D.ifstream fin(“A: abc.txt”,ios:: nocreate);
第11题:
第12题:
ifstream fin;fin.open(“d:\\test.txt”,ios_base::in);
fstmam fin;fin.open(“d:\\test.txt”,ios_base::out);
ofstream fout;fout.open(“d:\\test.txt”,ios_base::out);
ofstream fout;fout.open(“d:\\test.txt”,ios_base::app);
第13题:
下列程序从保存整数的文本文件”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;
}
第14题:
对于下面的程序: 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( ) ;
第15题:
以下程序的输出结果是( )。 #include<iostream.h> main() { int m=5; if(m++>5) cout<<m; else cout<<m--; }
A.7
B.6
C.5
D.4
第16题:
若磁盘上已存全路径文件名为c:\ctest\test.txt的文件,下面语句中不能打开该文件的是( )。
A.ifstream *pFile=new ifstream("c:\\ctest\\test.txt");
B.ifstream file("c:\\ctest\\test.txt");
C.ifstream file;file.open("c:\\ctest\\test.txt");
D.ifstream file("c:\etest\test.txt");
第17题:
下面程序的输出是 main() {int x=100, a=10, b=20, ok1=5, ok2=0; if(a<b) if(b! =15) if( ! ok1) else if(ok2) x= 10 x=-1 cout<<x<<end1; }
A.-1
B.0
C.1
D.不确定的值
第18题:
要建立文件流并打开当前目录下的文件6le.dat用于输入,下列语句中错误的是( )。
A.ifstream fin=ffstream.open(”file.dat”);
B.ifstream*fin=new ifstream(”file.dat”);
C.ifstream fin;fin.open(”file.dat”);
D.ifstream*fin=new ifstream;fin->open(”file.dat”);
第19题:
若磁盘上已存在某个文本文件,其全路径文件名为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");
第20题:
若磁盘上已存在某个文本文件,其全路径文件名为d:\shiti\tes.txt,下列语句中不能打开该文件的是( )。
A.ifstream file("d:\shiti\test.txt");
B.ifstream file("d:\\shiti\\test.txt");
C.ifstream file;file.open("d:\\shiti\\test.txt");
D.ifstream* pFile = new ifstream("d:\\shiti\\test.txt");
第21题:
对于下面的程序,说法正确的是 #include<iostream.h> void main( ) { int x=3,y=4,z=2; if(X=y+z) cout <<"x=y+Z"; else cout<<"x!=y+Z";}
A.不能通过编译
B.输出6
C.输出x! =y+z
D.输出x=y+z
第22题:
对于下面的程序 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();
第23题:
ifstream fin=ifstream.open(“file.dat”);
ifstream* fin=new ifstream(“file.dat”);
ifstream fin; fin.open(“file.dat”);
ifstream* fin=new ifstream(); fin->open(“file.dat”);