ifstream problem

Nov 16, 2012 at 1:22am
Hi,
I'm having some trouble with a couple of ifstreams.
I need to read in two files, and so I basically repeat a piece of code that I know works. However, for some reason, the second time around, it reads in garbage (stuff that's not a number (nan)).

Here's the code:

1
2
3
4
5
6
7
8
ifstream two("gs.txt");
    two.getline(filler2, 999);
    while(two >> date2 >> open2 >> high2 >> low2 >> close2 >> volume2 >> price2[i])
        {
            i++;
        }
    two.close();
    two.clear();


and then the second one that follows a couple of lines later is identical, but with different names and so on. But the structure is the same.

So, the first one works, and if I try to comment out the first one, the second works just like it should. But somehow, they don't work together. I've been trying to 'close' the files in different ways without luck.

Do you see what's going on here?
Nov 16, 2012 at 6:59am
Do you see what's going on here?
No, how? That code obviously doesn't produce the problem

Post the whole code where the problem can be reproduced.
Nov 16, 2012 at 5:23pm
and a couple lines from the data file.
Topic archived. No new replies allowed.