相关疑难解决方法(0)

863
推荐指数
7
解决办法
89万
查看次数

发现此文件中的错误读取代码(C++)

任何人都可以告诉我为什么这个方法不会编译?

void Statistics::readFromFile(string filename)
{
    string line;
    ifstream myfile (filename);
    if (myfile.is_open())
    {
        while (! myfile.eof() )
        {
            getline (myfile,line);
            cout << line << endl;
        }
        myfile.close();
    }

    else cout << "Unable to open file"; 

}
Run Code Online (Sandbox Code Playgroud)

应该工作吧?但是,我总是收到以下错误消息:

Line Location Statistics.cpp:15: error:
   no matching function for call to
   'std::basic_ifstream<char, std::char_traits<char> >::
      basic_ifstream(std::string*)'
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

c++ file-io

2
推荐指数
2
解决办法
5612
查看次数

标签 统计

c++ ×2

char ×1

const ×1

file-io ×1

string ×1