reading file with numbers into a vector

Sorry I could not debug my stuff, cause I have just changed to codeblocks from VS and is not familiar with windbg debugger yet (which looks crappy at first glance). So the problem is that the following piece of code does not work. I mean it compiles but does not result in what I expect from it. It seems tmp variable gets rubbish. What do I do wrong? Thanks.
1
2
3
4
5
6
7
	vector<double> p2;
	double tmp;
	
	ifstream fp("p2.dat", ios::in); //file does exist and opens properly
	for(fp >> tmp; !fp.eof(); fp >> tmp)
		p2.push_back(tmp);
	fp.close();
To run the debugger from CodeBlocks press F8
Are you sure that the file is formatted properly?
For these things you shouldn't use a for but a while:
1
2
while ( fp >> tmp )
    p2.push_back(tmp);

Indeed that is more elegant, I did not know I could use fp >> tmp as a condition. Thank you.

The problem was in reusing the stream for another file and forgetting to clear it to set the iterator to the begining of the stream. I am would delete the thread a bit later if that is possible.
I had the same problem with codeblocks and switched right back to visual studio express. I hate the debugger and there is no way to reconfigure the hotkeys to be more visual studio like. However, I was able to figure out the new buttons fairly quickly. I think that it is fairly intuitive to figure out but it is quite a bit different from visual studio. You should take another shot at it and practice with the debugger if you plan on continuing to use code blocks.
I hate the debugger
GNU debugger is not worse than the VC++ one http://www.cplusplus.com/forum/general/13360/
there is no way to reconfigure the hotkeys to be more visual studio like
There is: Settings > Editor > Keyboard shortcuts
( On Linux you need to install an additional package called something like codeblocks-contrib )
Hold on a second. That thread never declared a tie. There are useful things VCDB can do that gdb can't.
Topic archived. No new replies allowed.