PhoenixZq
分享是一门艺术~~
#include <iostream> 
#include <fstream> 
#include <string> 
using namespace std; 

int main() 
{ 
	const char filename[]="f:\\text.txt"; 
    ofstream o_file;
    ifstream i_file;
    string out_text; 

	//写 
    o_file.open(filename); 
    for(int i =0;i<=12;i++) 
	{ 
		o_file<< "a" << i <<' ';//将内容写入文本 
	} 
    o_file.close(); 

	//读 
    i_file.open(filename); 
    if(i_file.is_open()) 
	{ 
		while(i_file>>out_text)  
			cout << out_text << endl; 
	} 
	else 
		cout<<"打开文件:"<<filename<<"时出错!"; 

	i_file.close();
	return 0; 
} 

  

posted on 2011-10-13 22:12  PhoenixZq  阅读(2749)  评论(0编辑  收藏  举报