您的位置:首页 > 编程语言 > C语言/C++

C++如何读取txt文件,文件比较大想一行一行的读。

2007-08-07 20:16 429 查看
==========================

#include   <fstream>  
  #include   <string>  
  //   ..  
  string   filename;       //   the   file   name   you   want   to   open  
  string   lines;         //   store   the   file   lines  
   
  //   ...  
  ifstream   in(filename);  
  if   (in)   {  
        while   (getline   (in,   lines))     //   have   no   '/n',  
      {    
            //   ;  
          //   store   the   lines   to   a   vector   or   list,   use   method   insert  
        }  
   
  //   ...  
  }  
  else  
  {  
        //   open   file   fail....  
  }

========================= =

ifstream   OpenFile("a.txt");  
  OpenFile.getline(String,"/n",size);  
  OpenFile.close();

================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息