Chinaunix首页 | 论坛 | 博客
  • 博客访问: 91155
  • 博文数量: 22
  • 博客积分: 486
  • 博客等级: 下士
  • 技术积分: 262
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-07 19:26
文章分类

全部博文(22)

文章存档

2012年(22)

我的朋友

分类: C/C++

2012-03-31 14:18:27

#include
#include

using namespace std;
int main()
{
ifstream in;
in.open("file1.txt"); //打开一个文件
char c;
if(!in) //提示
{
cerr<<"open failure!\n"<
}
while(in>>c) //从文件最开始读。把读到的字符放到in
{
cout<//读一个显示一个。
}
cout<//结束
in.close(); //关闭文件
return 0;
}

 

从文件里写入
#include
#include

using namespace std;
int main()
{
ofstream out; //
out.open("file1.txt"); //打开一个文件
if(!out) //提示
{
cerr<<"open failure!\n"<
}
for(int i=0;i<10;i++)
{
out< }
cout<//结束
out.close(); //关闭文件
return 0;
}
阅读(288) | 评论(0) | 转发(0) |
0

上一篇:C 语言指针。。

下一篇:简单的宏定义

给主人留下些什么吧!~~