ifstream 有一个getline() 函数 逐行读取

但是该函数不支持string类型

getline(char *p,int); 这样 必须 char[] 来做缓冲区,

学习Console程序时 , 用到过

string line;

cin >>line;

还有一种方法是
std::getline(cin,line);


那么在 ifstream 中也可以使用次方法

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main(int argc,char **argv){
    ifstream out;
    string str = "d:\\text.txt";
    out.open(str.c_str(), ios::in);
    string line;
    while(!out.eof()){
        std::getline(out,line);
        cout <<line<<endl;
    }
    out.close();
    return 0;
}