data base search
Feb 26, 2012 at 11:55pm UTC
I have a database with hundreds of lines that looks something like this:
1 2 3 4 5 6 7 8 9 10 11
0.335634 0.014159 249.598008 0.499504 -0.853303 -0.149564
0.147345 0.188289 13.938972 0.403825 -0.895824 0.185539
0.143318 0.004027 28.212288 -0.651800 0.702521 -0.285693
0.135454 0.007864 60.864681 -0.485362 0.869942 0.087318
0.122921 0.012533 9.221047 -0.894950 0.425655 -0.133723
0.085982 0.036939 43.936591 -0.220456 0.975142 -0.022287
0.082738 0.003245 83.907961 0.771977 -0.629434 0.088680
0.078883 0.003855 64.282467 0.524386 -0.652417 -0.547149
0.000000 0.078882 16.490015 0.061913 -0.997716 -0.027006
end
After my main program reads through the entire program I want it to go back to the beginning and start reading from the top again. I have been trying to implement this using an if loop like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ifstream myfile("C:\\file" );
while (1)
{
getline(myfile, line);
.
.
.
if (line == "end" )
{
ifstream myfile("C:\\file" );
continue ;
}
}
That does not seem to work. I also tried
1 2 3 4 5
if (line == "end" )
{
myfile.seekg(0, ios::beg);
continue ;
}
That does not seem to work either. Any suggestions?????? I can't seem to get it...
Last edited on Feb 26, 2012 at 11:56pm UTC
Feb 27, 2012 at 5:20pm UTC
Should work. For the first example you should close the file before re-opening it.
Are you sure that the line read contains exactly "end" and no other crud? (\r\n spaces etc)
Topic archived. No new replies allowed.