关于C++文件读写的一些东西
2005-08-29 10:58
615 查看
#include <fstream.h>
int main()
{
ofstream fout("test");//建立流对象
if(!fout)
{
cout<<"cannot open output file./n";
return 1;
}
fout<<10<<" "<<123.456<<"/"This is a text file/"/n";
fout.close();
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <fstream.h>
int main()
{
ofstream fout("test2");
if(!fout)
{
cout<<"cannot open output file./n";
return 1;
}
fout<<"hello!/n";
fout<<100<<' '<<hex<<100<<endl;
fout.close();
ifstream fin("test2");
if(!fin)
{
cout<<"cannot open input file./n";
return 1;
}
char str[80];
int i;
fin>>str>>i;
cout<<str<<" "<<i<<endl;
fin.close();
return 0;
}
程序运行后,首先建立一个输出文件TEST2,并向它写如数据,HELLO!,100 64
关闭输出文件TEST2,再将它按输入模式打开,并将字符串“HELLO!”赋给STR,再将整数100赋给I,
最后在屏幕上显示HELLO 100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main()
{
ofstream fout("test");//建立流对象
if(!fout)
{
cout<<"cannot open output file./n";
return 1;
}
fout<<10<<" "<<123.456<<"/"This is a text file/"/n";
fout.close();
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <fstream.h>
int main()
{
ofstream fout("test2");
if(!fout)
{
cout<<"cannot open output file./n";
return 1;
}
fout<<"hello!/n";
fout<<100<<' '<<hex<<100<<endl;
fout.close();
ifstream fin("test2");
if(!fin)
{
cout<<"cannot open input file./n";
return 1;
}
char str[80];
int i;
fin>>str>>i;
cout<<str<<" "<<i<<endl;
fin.close();
return 0;
}
程序运行后,首先建立一个输出文件TEST2,并向它写如数据,HELLO!,100 64
关闭输出文件TEST2,再将它按输入模式打开,并将字符串“HELLO!”赋给STR,再将整数100赋给I,
最后在屏幕上显示HELLO 100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
相关文章推荐
- 【C/C++】C语言中一些容易被人忽略的东西 之六 【文件读写,y上两点】
- 关于标准C文件流读写问题:fopen,fread,fwrite,fclose的一些注意事项
- 关于C++的一些东西
- 关于C和C++分别读写TXT数据文件的源代码
- 关于链表的C++文件读写
- 关于Windows程序的一些东西(断点、头文件)
- 关于C/C++语言中头文件的使用的一些看法
- 关于C++如何读写txt文件
- C/C++ 关于如何读写ini配置文件
- C++中关于文件的读写
- C++ 文件读写的一些方法
- 关于c++模板的一些东西
- C/C++关于文件的读写操作以及文件的打开和保存
- c++关于文件的读写操作
- [转]一些关于linux下编译C++程序的东西
- [置顶] 关于C++中STL的一些东西(不定期整理)
- 关于链表的C++文件读写
- 关于C++工程 vcproj文件的的一些认识
- 关于多线程文件读写的一些博文
- 关于C++中输入输出的小结——读写文件、string