Hello guys. I have developed a program which is supposed to read several times from the same file. I have used clear() and seekg() but nothing works. When the file gets open for the second time the program doesn't read anything from it. I would appreciate any suggestions. Here is the code:
case 1: sm = new SearchingMap();
m = sm;
(*m).initializeGraph();
nodes.open("..\\location.txt");
if (nodes.fail ())
{
cerr << "*** ERROR: Cannot open file" ;
return EXIT_FAILURE; // failure return
}
nodes.seekg(0, ios::beg);
while(nodes >> val >> delimiter && i < 10)
{
getline(nodes, descr);
(*m).inputVertex(val, descr, i);
i++;
}
nodes.close();
nodes.clear();
edges.open("..\\edge.txt");
if (edges.fail ())
{
cerr << "*** ERROR: Cannot open file" ;
return EXIT_FAILURE; // failure return
}
edges.seekg(0, ios::beg);
while(edges >> row >> delimiter >> val >> delimiter && j < 50)
{
getline(edges, descr,':');
edges >> col;
(*m).inputEdge(val, descr, j);
(*m).inputGraph(row - 1, col - 1, descr);
j++;
}
edges.close();
edges.clear();
cout << "The possible locations you can choose from are:\n\n";
(*m).printVertex();
cout << endl;
cin.ignore(INT_MAX,'\n');
while(1)
{
cout << "Enter your initial position: ";
getline(cin, init);
if((*m).searchGraph(init) == -1)
{
cin.clear();
cin.ignore(INT_MAX,'\n');
continue;
}
break;
}