"hivie" <hi*******@yahoo.com> wrote in message
news:49**************************@posting.google.c om...
I have a problem that is causing me problems. I have a text file that
stores 5 lines of crap (stuff that I dont need( for the user only)).
After that there is data that is in three columns separated by lots of
whitespace. I dont think that the bytes are uniform ( I tried
TextReader.readblock). Sorry, I am using VC++ .net. I only need the
first two columns that are both double values. I need to either read
those two columns into a mulit-Dim array or be able to search the
file expeditously at runtime. The searchable value is the value in
the first column. Can someone give some direction please???
Thank you
hivie
What is TextReader.readblock? You'll only get a answer in standard C++ here.
What's in the third column? This is going to have to be read, even though
you don't need it.
Your searching requirements would be best dealt with using a std::map
#include <map>
std::map<double, double> my_map;
Much, much more efficient than an array. If you need to hold duplicate
values for the first column, then use a multi_map instead of a map.
Something like this? (untested)
#include <fstream>
#include <string>
#include <map>
ifstream my_file("myfile.txt");
std::map<double, double> my_map;
string dummy;
// skip file lines
for (int i = 0; i < 5; ++i)
getline(my_file, dummy);
double col1, col2;
while (my_file >> col1 >> col2)
{
my_map[col1] = col2;
if (!getline(my_file, dummy)) // skip rest of line
break;
}
You should investigate map::lower_bound, map::upper_bound and
map::equal_range for searching the map. Searching a map, whose key is a
double, for exact values is unlikely to work.
john