Code does not exit while(getline) loop

C++ community, I have a problem with my program not executing beyond the while loop. I have read about the topic, and know that while(get line(myFile, line) should be considered false if the end of the file has been reached. My problem is that the code won't get out the while loop. Please help me. I am using Xcode on a mac.
Text File:
1
4 11111

Output generated:
1
4 11111

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 string line;
 ifstream myFile ("useme.txt");
    if (myFile.is_open()){
        while (getline(myFile, line)){
            
            cout << line << '\n';
            change[counter] = line;
            counter++;
            
            }
        myFile.close();
        
    }
    else{
            cout << "Unable to open file";
    }
    int cases = atoi(change[0].c_str());
    cout << "Number of cases " << cases;
Last edited on
Can you show us of what type "line" is?

Becuase this works fine for me, it exists the loop.
Last edited on
line is string
Topic archived. No new replies allowed.