// file-stream-coupling.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//open file "example.dat" for reading and writing
filebuf buffer;
ostream output(&buffer);
istream input(&buffer);
buffer.open("example.dat", ios::in|ios::out|ios::trunc);
for(int i=1;i<=4;i++){
//write one line
output<<i<<".line"<<endl;
//print all file contents
input.seekg(0);
char c;
while(input.get(c)){
cout.put(c);
}
cout<<endl;
input.clear();//clear eofbit and failbit
}
system("pause");
return 0;
}