我虽然这可以ifstream继承自从继承istream
string getFileContents(istream& file_contents)
{
string result;
string line;
while (getline(file_contents, line))
result += line + "\n";
return result;
}
Run Code Online (Sandbox Code Playgroud)
然后我想这样调用这个函数:
ifstream file_input;
getFileContents(file_input);
...
getFileContents(cin);
Run Code Online (Sandbox Code Playgroud)
但是我在visual studio中遇到了这个错误:
'getFileContents':无法将参数1转换std::istream为std::ifstream &
| 归档时间: |
|
| 查看次数: |
19691 次 |
| 最近记录: |