C++读取txt文件里每行的数据

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

const char *board_list = "./example_list.txt";

int main(int argc, char **argv)
{
    FILE *f = fopen(board_list, "rt");
    
    for (;;)
    {
        char buf[1024];
        if (!fgets(buf, sizeof(buf) - 3, f))
            break;
        size_t len = strlen(buf);
        while (len > 0 && isspace(buf[--len]));
        buf[len+1] = '\0';
        cout<<buf<<endl;
    }
    return 0;
}