6
我儘管這會因爲ifstream
繼承工作從istream
如何通過CIN或ifstream的對象作爲參數功能
string getFileContents(istream& file_contents)
{
string result;
string line;
while (getline(file_contents, line))
result += line + "\n";
return result;
}
那麼我想調用這個函數像這樣:
ifstream file_input;
getFileContents(file_input);
...
getFileContents(cin);
,但我得到visual studio中出現此錯誤:
'getFileContents':無法將參數1從std::istream
轉換爲std::ifstream &
hah woops ..是的原型是錯的。我的錯。 – ladookie 2011-02-12 21:48:27