习题10和其解答(第二版).doc

  1. 1、本文档共7页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第10章 输入/输出流 习题10 10.1 选择题 1.下列流类中可以用于处理文件的是( d )。 (a) ios (b) iostream (c) strstream (d) fstream 2.在下列选项中( b )是istream类的对象。 (a) cerr (b) cin (c) clog (d) cout 3.read函数的功能是从输入流中读取( d )。 (a) 一个字符 (b) 当前字符 (c) 一行字符 (d) 指定若干个字节 4.下列选项中,用于清除基数格式位设置以十六进制输出的语句是( b )。 (a) cout setf( ios::dec, ios::basefield ) ; (b) cout setf( ios::hex, ios::basefield ) ; (c) cout setf( ios::oct, ios::basefield ) ; (d) cin setf( ios::hex, ios::basefield ) ; 5.下列格式控制符,既可以用于输入,又可以用于输出的是( a )。 (a) setbase (b) setfill (c) setprecision (d) setw 6.下列串流类,在strstream.h中定义的是( b )。 (a) istringstream (b) istrstream (c) ostringstream (d) stringstream 7. 包含类fstream定义的头文件是( a )。 (a) fstream.h (b) ofstream.h (c) ifstream.h (d) iostream.h 8.要求打开文件 D:\file.dat,并能够写入数据,正确的语句是( d )。 (a) ifstream infile( “D:\\file.dat”, ios::in ) ; (b) ifstream infile( “D:\\file.dat”, ios::out ) ; (c) ofstream outfile( “D:\\file.dat”, ios::in ) ; (d) fstream infile( “D:\\file.dat”, ios::in | ios::out ) ; 9.设已定义浮点型变量data,以二进制方式把data的值写入输出文件流对象outfile中去,正确的语句是( c )。 (a) outfile.write((double *) data, sizeof(double)) ; (b) outfile.write((double *) data, data) ; (c) outfile.write((char *) data, sizeof(double)) ; (d) outfile.write((char *) data, data) ; 10.2 阅读下列程序,写出执行结果 1. #include iostream.h void main() { double x = 123.456; cout.width( 10 ); cout.setf( ios :: dec, ios :: basefield ); cout x endl; cout.setf( ios :: left ); cout x endl; cout.width( 15 ); cout.setf( ios::right , ios::left ); cout x endl; cout.setf( ios::showpos ); cout x endl; cout -x endl; cout.setf( ios :: scientific ); cout x endl; } 【答案】 123.456 123.456 123.456 +123.456 -123.456 +1.234560e+002 2. #include iostream.h void main() { double x = 123.45678; cout.width( 10 ); cout ( # ); cout x endl; cout.precision( 5 ); cout x endl; cout.setf( ios::showpos ); cout x endl; cout.setf( ios::sci

文档评论(0)

kehan123 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档