473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Searching text files

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
Jul 19 '05 #1
3 7218

"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
Jul 19 '05 #2
"John Harrison" <jo*************@hotmail.com> wrote in message news:<be************@ID-196037.news.dfncis.de>...
"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


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
Jul 19 '05 #3
>
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
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
Hi everyone ! This is a first time I post a message here. If I post my message in a wrong group. Please ignore it. I am trying to build a website which allows users (can be thousands of...
2
by: Kakarot | last post by:
I'm gona be very honest here, I suck at programming, *especially* at C++. It's funny because I actually like the idea of programming ... normally what I like I'm atleast decent at. But C++ is a...
1
by: Dave S | last post by:
Hello all, Hope this is the correct group for this question. I couldn't find a vb beginners group. I am getting overwhelmed and need some help. I did this very easily in a batch file (only three...
2
by: Mark Reed | last post by:
Hi all, I don't know if this is do-able but you never know until you ask. A situation at work has arisen where I have to trawl through over 500 text files, copy the contents and then paste them...
1
by: Bud Dean | last post by:
I need to search files for given text. In particular, I'm searching dll's, exe's, asp, aspx and html pages. I am having difficulty converting the byte arrays to strings. The following code...
0
by: hatcat | last post by:
Hi everyone. I'm looking for the right tool for a job. Hope someone can help. The deal is this: We have a large amount of data which is maintained by non-programmers. This is validated and...
4
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given...
15
by: spazzo6281 | last post by:
Hello, is there a way to search a folder for certain files containing a wildcard or certain text entered into a text box. Right now all i can get is the whole list of files from a folder using the...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.