对文件读取以及写入的一个小例子

// container.cpp : 定义控制台应用程序的入口点。

//

 

#include "stdafx.h"

#include<fstream>

#include<iostream>

#include<string>

#include<stdexcept>

#include<vector>

 

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

  string a="in.txt";

  string b="out.txt";

  ifstream infile(a.c_str());

  if(infile)

  {

     cout<<"哟,竟然这个输入文件存在这里"<<endl;

     string ingood;

     infile>>ingood;

     cout<<ingood<<endl;

  }

  ofstream outfile(b.c_str(),ofstream::app);

  if(outfile)

  {

     string outname="这是我要输出的东西哦";

     outfile<<outname;

  }

 

  return 0;

}

 

原文地址:https://www.cnblogs.com/crazycodehzp/p/3344705.html