首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

C++ Again(一):文件读入与写出

2013-11-01 
C++ Again(1):文件读入与写出本文章的实现参考自C Primer第一章第5节。当前的任务是实现一个C程序,能够从

C++ Again(1):文件读入与写出

本文章的实现参考自<C++ Primer>第一章第5节。

当前的任务是实现一个C++程序,能够从某个文件读入字符串并将字符串写入到另一个文件中。

实现代码如下:

#include <iostream>#include <fstream>#include <string>using namespace std;int main(){ // ofstream outfile("out_file"); // ifstream infile("in_file");ofstream outfile;ifstream infile;outfile.open("out_file",ios::app);infile.open("in_file");  if(! infile){      cerr<<"error:unable to open file"<<endl;  return -1;  }  if(! outfile){      cerr<<"error:unable to open outfile"<<endl;  return -2;  }  string word;  while(infile >> word)  outfile << word << '~';  return 0;}

热点排行