c++初试-文件流(9)

/*
 * file.cpp
 *
 *  Created on: 2014年10月31日
 *      Author: Administrator
 */
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main(){
	//写文件
	string filename = "E:/aa.txt";
	ofstream fout(filename.c_str());
	fout << "hello world" << endl;
	fout.close();


	//读文件
	ifstream fin("E:/aa.txt");
	char ch;
	while(fin.get(ch)){
		cout << ch;
	}
	cout << endl;
	fin.close();
	return 0;
}




你可能感兴趣的:(C++)