#include <iostream>
#include <fstream>

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

 

从文件里写入
#include <iostream>
#include <fstream>

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



 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2018-09-09
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案