读取和写入文件

#include <fstream>
#include <iostream>
using namespace std;

void main()
{
	char buf[1024*50]={0};

	//读
	ifstream inFile;
	inFile.open("cloudComputing.txt");
	//inFile.open("D:\\testout.dat",ios::in);
	int arr =0;
	while (inFile.good())
	{
		inFile>>buf[arr];
		arr++;
	}
	inFile.close();

	//写
	ofstream outFile;
	//outFile.open("D:\\testout.dat",ios::out);
	outFile.open("D:\\cloudComputingNew.txt",ios::app);//ios::app表示在文件末尾写
	for (int i =0; i<= arr; i++)
	{
		outFile<<buf[i];
	}
	outFile.close();
}

  参见:https://www.cnblogs.com/ifeiyun/articles/1573134.html

posted @ 2017-02-08 17:42  那一剑的風情  阅读(221)  评论(0编辑  收藏  举报