实验七-C++的输入输出流库_第1页
实验七-C++的输入输出流库_第2页
实验七-C++的输入输出流库_第3页
实验七-C++的输入输出流库_第4页
实验七-C++的输入输出流库_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1从键盘输入一个字符串 并逐个将字符串的每个字符传送到磁盘文件中 字符串的结束 标记为 include include include using namespace std void main ofstream myf e aaa txt char txt 1000 int i cin getline txt 100 for i 0 i 100 i if txt i break myf txt i 2 输出十进制 八进制 十六进制显示的数据 0 15 include include using namespace std void main int i int shuzu 16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 cout Decimal for i 0 i 16 i cout dec shuzu i cout endl cout Octal for i 0 i 16 i cout oct shuzu i cout endl cout Hexadecimal for i 0 i 16 i cout hex shuzu i cout endl 3 类 stu 用来描述学生的姓名 学号 数学成绩 英语成绩 分别建立文本文件和二进制 文件 将若干学生的信息保存在文件中 读出该文件的内容 include include using namespace std class student public char name 10 int num float math float english friend ostream ostream return in void main ofstream ofile ifstream ifile ofile open e d txt student s int a cout a cout endl for int i 1 i a i cout 请输入第 i 个学生的姓名 学号 数学成绩 英语成绩 s ofile s ofile close ifile open e d txt cout n读出文件内容 s while ifile eof cout s ifile close 4 设计一个留言类 实现以下的功能 1 程序第一次运行时 建立一个 message txt 文本文件 并把用户输入的信息存入该文件 2 以后每次运行时 都先读取该文件的内容并显示给用户 然后由用户输入新的信息 退出时将新的信息存入这个文档 文件的内容 既可以是最新的信息 也可以包括以前所 有的信息 用户可自己选择 include include using namespace std class Message public char msg 20 friend ostream ostream return in void main ofstream ofile ifstream ifile Message s int option ifile open e message txt ios Nocreate if ifile fail 第一次运行建立文件 输入信息 ofile open e message txt cout 请输入一条信息 s ofile s ofile close ifile close else 以后运行首先显示文件内容 cout 文件的内容为 s while ifile eof cout s ifile close for 显示菜单以供用户进行选择 cout 请选择 endl 1 追加信息 endl 2 覆盖原有信息 endl 3 显示文件信息 endl 0 退出 option switch option case 1 ofile open e message txt ios app cout 请输入一条信息 s ofile s ofile close break case 2 ofile open e message txt ios trunc c

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论