msietrterc
msietrterc

Reputation: 87

C++ Filie i/o read two ints at once

I have a text file with numbers in pairs in the form

1 5 6 8 9 7

or

3 4

All the files have a even number of numbers. How can I get allways the next two ints instead of just one?

ifstream inFile;
inFile.open(...);
int n;
while (inFile >> n) {
    int m;
    inFile >> m;
    pb.import(n, m);
}

This gives a type error for m.

pb.import requires two ints.

Thanks

Upvotes: 0

Views: 48

Answers (1)

Barry
Barry

Reputation: 303800

Just read two ints at a time:

int n, m;
while (inFile >> n >> m) {
    pb.import(n, m);
}

Upvotes: 6

Related Questions