【发布时间】:2011-04-12 13:09:38
【问题描述】:
我知道还有其他一些类似的帖子,但我已经在这个单一错误上运行了一个多小时,无法弄清楚。这是造成麻烦的代码
istream& operator>>(istream& in, UndirectedGraph& g)
{
int numVerticies;
in >> numVerticies;
g = UndirectedGraph(numVerticies);
for(int i = 0; i < numVerticies; i++)
{
int temp;
in >> temp;
if(temp != i)
{
g.linkedAdjacencyList[i]->value = temp;
}
}
int edges;
in >> edges;
g.edges = edges;
for(int i = 0; i < edges; i++)
{
int first;
int second;
in >> first >> second;
addEdge(first, second);
}
return in;
}
ostream& operator<<(ostream& out, UndirectedGraph& g)
{
out << g.numVerticies << endl;
for(int i = 0; i < g.numVerticies; i++)
{
out << g.linkedAdjacencyList[i] << " ";
}
out << endl;
out << g.edges << endl;
for(int i = 0; i < g.numVerticies; i++)
{
out << linkedAdjacencyList[i]->value;
Node* whereto;
whereto = linkedAdjacencyList[i]->adj;
while(whereto->adj != NULL)
{
out << " " << whereto->value;
whereto->adj = whereto->adj->adj;
}
}
return out;
}
int main()
{
ifstream inFile;
inFile.open("hw8.in");
UndirectedGraph graph;
inFile >> graph;
...
这里,错误在第 1 行和第 28 行,istream 和 ostream 重载。
感谢您的帮助!
【问题讨论】:
-
第 1 行和第 28 行是什么?
-
@Daniel istream 和 ostream 声明