0

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;
}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by blerina12
0

So, what doesn't work? edges.open(); ? Double check the filepath please, hehe. Code looks okay, you won't need to clear it, unless errors occurred and you've recovered from them (or just want to reset them of course).

0

So, what doesn't work? edges.open(); ? Double check the filepath please, hehe. Code looks okay, you won't need to clear it, unless errors occurred and you've recovered from them (or just want to reset them of course).

You were right. I had forgotten to reset i and j. Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.