file io error

for some reason it does not like my syntax for opening a file. i have to do it for two separate files and the first one works fine, however when i try and open the second file to read the information using the exact syntax from the first one i get an error saying it cant open the file


it works on the "CityName.txt" but not when you try to open the "FlightPath.txt"
any suggestions?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void Map::readMap()
{
    string name1;
    string name2;

    int i = 1;
    ifstream Din;
    Din.open("CityName.txt");
    if (!Din)
        cout << "ERROR";
    else
        while (Din >> name1)
        {
           cityNames[i] = name1;
           number[i];
           numberOfCities++;
           i++;
        }
    Din.close();
    
    Din.open("FlightPath.txt");
    if (!Din)
        cout << "ERROR";
    else
        while (Din >> name1)
        {
           Din >> name2;
           numberOfFlights++;
           insertAdjacent(cityNumber(name1), cityNumber(name2));
        }
    Din.close();
}
The file stream is still marked bad/failed from the first operation.
Do Din.clear() before opening the second file.

1
2
    Din.clear();
    Din.open("FlightPath.txt");
thank you much that fixed it
Topic archived. No new replies allowed.