Please help me undersatnd why this code does no work, even when it compiled without problems. After I have input the filename the application just hangs up and aborts thereafter. My input file contains the graph' adjacency matrix and the application is supposed to pull this data from the file to create a graph object. Any explanations about whats wrong will be greatly appreciated.
Here is the function code for refence:
template<class vType, int size>
void graphType<vType, size>::createGraph()
{
ifstream infile;
char fileName[50];
vType vertex;
vType adjacentVertex;
if(gSize != 0) //if the graph is not empty, make it empty
clearGraph();
cout<<"Enter the input file name: ";
cin>>fileName;
cout<<endl;
infile.open(fileName);
if(!infile)
{
cerr<<"Cannot open the input file."<<endl;
return;
}
infile>>gSize; //get the number of vertices
for(int index = 0; index < gSize; index++)
{
infile>>vertex;
infile>>adjacentVertex;
while(adjacentVertex != -999)
{
graph[vertex].insertLast(adjacentVertex);
infile>>adjacentVertex;
}//end while
}//end for
infile.close();
}//end createGraph