欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C++中簡(jiǎn)單讀寫文本文件的實(shí)現(xiàn)方法

 更新時(shí)間:2013年05月29日 16:14:28   作者:  
本篇文章是對(duì)C++中簡(jiǎn)單讀寫文本文件的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
代碼如下所示:
復(fù)制代碼 代碼如下:

#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
 //寫入文件
 ofstream ofs;  //提供寫文件的功能
 ofs.open("d:\\com.txt",ios::trunc); //trunc打開文件時(shí),清空已存在的文件流,若不存在此文件則先創(chuàng)建
 int i;
 char a = 'a';
 for(i = 1; i != 27; ++i)
 {
  if(i < 10)
  {
   ofs << "0" << i << "\t" << a << "\n";
   a ++;
  }
  else
  {
   ofs << i << "\t" << a << "\n";
   a ++;
  }
 }
 ofs.close();
 //讀出文件到控制臺(tái)
 char buffer[256];
 ifstream ifs; //提供讀文件功能
 ifs.open("d:\\com.txt",ios::in);//in--打開文件做讀操作
 cout << "d:\\com.txt" << "中的內(nèi)容如下:" << endl;
 while(!ifs.eof())  //判斷是否達(dá)到stream的結(jié)尾
 {
  ifs.getline(buffer, 256, '\n'); //字符達(dá)到256個(gè)或遇到換行就結(jié)束
  cout << buffer << endl;
 }
 ifs.close();
}

相關(guān)文章

最新評(píng)論