function with an istream& parameter C++

前端 未结 1 590
太阳男子
太阳男子 2021-01-07 15:19

I would like my program to read a file using the function \"readFile\" below. I am trying to find out how to call a function with an istream& parameter. The goal of the

相关标签:
1条回答
  • 2021-01-07 15:52

    The first argument to the std::ifstream constructor should be a string. You're trying to pass it a std::istream. Maybe the std::istream contains the name of the file you want to read, in which case you want to extract the name into a std::string first. Something like this might work:

    std::string fileName;
    name >> fileName;
    std::ifstream file(fileName, ios::in);
    
    0 讨论(0)
提交回复
热议问题