小白教你学习C++(9)文件流操作
来源:互联网 发布:java 线程池 等待队列 编辑:程序博客网 时间:2024/06/05 15:29
#include <iostream>
using namespace std;
void main()
{
char *fname ="c:/2.txt";
char *fname1 ="c:/2ttrtgg.txt";
ofstream fout(fname1,ios::app,iso::ate);
if(!fout)
{
cout<<"如果打开失败"<<endl;]
return;
}
ofstream fout(fname,ios::out);
fout <<"hello world"<<endl; //wrint a file
fout <<"hello world"<<endl;
fout <<"1232424ld"<<endl;
fout <<"hello world"<<endl;
fout.close();
ifstream fin(fname); //一输入的形式打开文件
cout <<"hello..."<<endl;
char ch;
while(fin.get(ch))
{
cout<<ch;
}
system(pause);
return;
}
class teacher
{
public:
private:
int age;
char name[];
teacher()
{
age=30;
strcpy(name,""
teacher(int _age,char *_name)
{
int age;
strcpy(name,_name);
}
void printf()
{
cout<<"name"<<name<<age<<"age"<,endl;
}
}
}
//二进制文件的打开和写入
void main()
{
char *fname1 ="c:/2ttrtgg.dat";
ofstream fout(fname1,ios::binary);
if(!fout)
{
cout<<"如果打开失败"<<endl;]
return;
}
teacher T1(31,t31");
teacher T2(32,"t32");
fout.write((char*)&t1,sizeof(t1))
fout.write((char*)&t2,sizeof(t2));
ifstream fin(fname);
Teacher tmp;
fin.read(char*)&%tmp,aizeof(Teacher));
tmp.printf();
fin.read(char*)&%tmp,aizeof(Teacher));
tmp.printf();
}
阅读全文
0 0
- 小白教你学习C++(9)文件流操作
- c语言学习第二天(c语言文件操作)
- 【C/C++】文件流操作
- 系统编程(文件操作)---C语言学习(2)
- C语言学习笔记系列(7)文件操作
- (C#)学习笔记1:文件和注册表操作
- linux c学习之文件操作(一)
- Linux C 学习之文件操作(二)
- C语言学习笔记(六)——文件操作
- C/C++流操作(文件,字符串)
- 文件的流操作(C)
- 基本文件流操作(C语言)
- C/C++日常学习总结(第十篇)string的实现&文件流操作
- C语言学习第十七天(文件操作)
- 学习C/C++语言:文件的操作
- C学习笔记10--文件操作
- Objective-C学习笔记-之操作文件
- C/C++ 学习之 文件操作
- 网络中获取json数据
- sqlite迁移到mysql脚本
- 题目:斐波那契数列
- Ionic初学习上遇到的问题
- 并查集
- 小白教你学习C++(9)文件流操作
- UE4 AI行为树简记
- seafile 迁移手册
- Struts2项目实战 微云盘(一):项目分析
- Java 注解1
- java图片处理以及pdf转图片
- macdown安装
- =号运算符,printf函数,进制输出的例题详解
- 8.5早做题感悟