473,698 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.read block). 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 7243

"hivie" <hi*******@yaho o.com> wrote in message
news:49******** *************** ***@posting.goo gle.com...
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.read block). 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.read block? 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_fi le, dummy)) // skip rest of line
break;
}

You should investigate map::lower_boun d, map::upper_boun d and
map::equal_rang e 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.dfn cis.de>...
"hivie" <hi*******@yaho o.com> wrote in message
news:49******** *************** ***@posting.goo gle.com...
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.read block). 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.read block? 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_fi le, dummy)) // skip rest of line
break;
}

You should investigate map::lower_boun d, map::upper_boun d and
map::equal_rang e 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
2529
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 users, supposedly) to upload their files to their designaged directories (max 15 files for each user). A super user (can be more than one) want to search for a particular file name and also a particular textual part of a file of all user's files in all...
2
8249
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 different story. Linked lists have been giving me a headache. I can barely manage to create a single/doubly linked list, it's just that when it gets to merge sorting or searching (by reading shit data from text files), I lose track.
1
7113
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 lines), but DOS is too limited and the use of the batch is presenting other problems (file is compressed so I get garbage characters in the output file which I can't edit). I also wanted some other functionality added and decided to try VB6.
2
1528
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 into an Excel sheet where it is analysed. Would it be possible to copy the files, paste them into a 'reserved' directory and get Access to import the contents of all the file in one go? The first line and last line of these text files would need to...
1
1470
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 identifies the file and line number where the text appears. It appears to work, but... I would appreciate any suggestions for improvement. heres the code: *********************Start Code ****************************
0
1351
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 exported to a series of text files. These text files are parsed into memory. Third parties are also able to modify these text files.
4
5342
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 the Identifier. The logical way would be to read the record once and put it in an STL container such as vector and then use lower_bound to search for a given identifier. But for some strange reason i'm asked to not use a container but instead...
15
2441
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 following code: lstbox.additems.addrange(IO.directory.getfiles("c:\")) How can i just return only files with matching text as whats in the text Box. Any help will be greatly appreciated. Thanks. Matt
12
2368
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 registry mark given by underwriters (as at Lloyd's) to ships in first-class condition. Inferior grades are indicated by A 2 and A 3. () The first three letters of the alphabet, used for the whole alphabet. () In church or chapel style; -- said of...
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.