使用ifstream

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream ifs("test.txt");
    // 是否读取成功
    if ( !ifs )
    {
        cout << "读取失败" << endl;
        return 0;
    }
    string line;
    while ( getline(ifs, line) )
        cout << line << endl;
    return 0;
}