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

程序将自己的源代码写入记事本

2012年11月16日 ⁄ 综合 ⁄ 共 375字 ⁄ 字号 评论关闭

这个例子利用了C++文件读写的功能,将main()函数输出到一个记事本中

#include<fstream>
#include<iostream>

using namespace std;

int main()
{
 fstream fin,fout;
 fin.open("main.cpp",ios::in);
 if(!fin)
 {
  cout<<"can't open file main.cpp !";
  return -1;
 }
 fout.open("main.txt",ios::out);
 if(!fout)
 {
  cout<<"can't open file main.txt !";
  return -1;
 }
 char ch;
 while(fin.get(ch))
  fout.put(ch);
 fin.close();
 fout.close();
 return true;
}

图片

抱歉!评论已关闭.