C++那个代码流有什么问题

C++ whats wrong with that code fstream

本文关键字:什么 问题 代码 C++      更新时间:2023-10-16

需要一些关于C++代码的帮助

    #include <iostream>
    #include <fstream>
    #include <string>
using namespace std;

    class open_file
    {
        string list_cont;
        fstream newlist;
        newlist.open("lista.txt",ios::in);
        while (newlist.good())
        {
            getline(newlist, list_cont);
            cout << list_cont << endl;
        }
        newlist.close();
    };

Visual Studio 不断给我错误 102 错误 C2143:语法错误:在"."

杜诺为什么,有什么想法吗?

提前致谢

class open_file替换为void open_file()并删除最后一个分号。您的问题是您正在尝试声明一个函数,但您使用了 class 关键字。