我有這段代碼:
void NeighborsList::insertVertexes(const ifstream & inputFile)
{
int tempS, tempT;
for (int i = 0; i < numOfVertexes; i )
{
inputFile >> tempS;
inputFile >> tempT;
addEdge(tempS, tempT);
}
}
我正在嘗試獲取檔案的輸入。一旦我洗掉了函式引數中的 const - (ifstream & inputFile) 它就可以作業了。
uj5u.com熱心網友回復:
給定一個const物件或參考,僅const操作可以被執行。std::istream::operator>>是不是一個const操作中,因此,它可能不能在此處使用。
這std::istream::operator>>不是const操作是有道理的,因為它改變了流的可觀察狀態。例如,檔案上的讀取位置以及狀態指示器(如fail和 )已更改eof。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/351594.html
上一篇:列印檔案前10行的問題
