现在的位置: 首页 > 综合 > 正文

标准C++ 读取写入文件代码

2013年10月09日 ⁄ 综合 ⁄ 共 496字 ⁄ 字号 评论关闭
#include <iostream>
#include <fstream>

using namespace std;
int main(void)
{

 ifstream inf("c:\\aa.txt");
 while (!inf.eof())
  {
   char ch;
   inf.get(ch);
   cout<<ch;
  }
 inf.close();
 return 0;
}
//---------------------------------------------------------------------------

//示例2,将输入的字符串写入一个TXT文件:

//---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
int main(void)
{
 string wd;
 ofstream outf("c:\\aa.txt");
 cin>>wd;

 outf<<wd;

 outf.close();
 return 0;
}

抱歉!评论已关闭.