Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Searching text files

Reply
Thread Tools

Searching text files

 
 
hivie
Guest
Posts: n/a
 
      07-08-2003
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
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-08-2003

"hivie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
hivie
Guest
Posts: n/a
 
      07-08-2003
"John Harrison" <(E-Mail Removed)> wrote in message news:<bedlv0$3rup5$(E-Mail Removed)>...
> "hivie" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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


Sorry, the textreader is a .net thing. I have never heard of "map",
but I am going to look into it. thanks for the direction!
Heath
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      07-08-2003
>
> Sorry, the textreader is a .net thing. I have never heard of "map",
> but I am going to look into it. thanks for the direction!
> Heath


std::map is a standard C++ class for an associative array.

john


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows 7, searching for all files containing a text string Matty F NZ Computing 25 12-14-2011 06:16 PM
Reading a number of files and and searching for text Paul Donaghy Ruby 2 04-26-2008 05:25 AM
Google search result to be URL-limited when searching site, but notwhen searching Web stumblng.tumblr Javascript 1 02-04-2008 09:01 AM
how i can extract text from the PDF files,power point files,Ms word files? crazyprakash Java 4 10-30-2005 10:17 AM
Searching text in Excel, Word files Rene Aguirre Python 0 03-03-2004 04:24 PM



Advertisments