473,387 Members | 1,582 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,387 software developers and data experts.

reading parameter file and parsing the contents

i need to read in parameter files of unknown length where the
parameters are given in pairs such as "key value" (without quotes). I
only recognize one pair per line and if I encounter a '#' I ignore
anything past the '#' and if an "end" I end the loop. This code works
fine but I want to apply it to other things.

I am new to C++ and I have the suspicion that there is a more elegant
way to do what I did. Before I use the same method in other places I'd
like to know how this could be improved and made "more correct" in
general, and specifically on how I searched for alphanums.
int ParameterFile_t::read( map<string,string>* ParameterTable )
{
string readout;
stromg alphanum =
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxY yZz1234567890_.,";
string read1;
string read2;
unsigned int start = 0;
unsigned int end = 0;
while( !parameterfile.eof() )
{
getline(parameterfile, readout);
unsigned int found;
if( (found = readout,find('#')) != string::npos )
readout.erase( found , readout.length() );

// get first string
if( (start = readout.find_first_of(alphanum )) == string::npos)
continue;
end = readout.find_first_not_of(alphanum,start);
read1 = readout.substr(start, end - start);

// is end?
if( read.compare("end") == 0 )
break;

// get second string
if( (start = readout.find_first_of(alphanum, end+1 )) ==
string::npos)
continue;
end = readout.find_first_not_of(alphanum,start);
read2 = readout.substr(start, end - start);

(*ParameterTable)[read1] = read2;
}
return 0;
}

Thanks, Chris.
and please forgive me if I'm in the wrong group.

Jul 23 '05 #1
2 3066
** edit :: "stromg alphanum" = should be "string alphanum ="

Jul 23 '05 #2
hello easy,
You should check out fstream class of the iostream header.
by that you can do the tokenizer much easier and basic too.
There are some complex tokenizer that you can get too. I have it too.
You know, you can do this parameter things easy. See the fstream bet,
I'll all be clear to you. (wonder how much money lost out for classes
to solve these simple questions, I was one of them eheh)
Edernity
--------
Edernity
--------
ALRIGHT I'M GIVING ALL THAT ALREADY READ THIS A CHANCE (THIS NG),
pls help. If my posting is useless I'll go. Remeber that God hate
miser.
if it help (IT DON'T CAUSE YOU A CENT. JUST 1 EMAIL THEN FILLING FORMS)
please do help me provide better school supplies for childrenof
indonesia.
IN FACT, for those other who already read this plea and maybe finding
my post helpful, what is I give you one dollars for it. I don't believe
this, I'm paying to get people to donate to kids?!!!???that really
ugly!
it may be a donation but I merely ask you to letme send email to you
from one of the product of I'm affiliated and please register there on
mechant account free. If you even want you refund back on your dollar
of i-kard, its ok, I'll send you just use regular delivery on shipping
please. Please note this is very safe since this is a bonafid company.
remember your credit card company will confirm you on your purchase.
u can add or remove more credit cards into your account. you can/should
also ask for always confirmation on send out to you. That will get
those savage cracker bloke out. even u can use some more free teen
refillable visa/mastercard from your bank cc account (can be obtaion
free).
It is just unnerving seeing how can people do not do anything as so
they need so little. $10 could support {{{{{the child 1 month.}}}}
Still have doubts, sign on a personal account and let me contact you
again on it. just one mail pls
also
I'm also affiliated to this site:
www.getaportal.com/portals/eddy_ruslim
Unless u wanto e-gold it at 1369872
New to egold:www.e-gold.com/e-gold.asp?cid=1369872
NAH, previous way cost u zilch
God bless
easy wrote:
** edit :: "stromg alphanum" = should be "string alphanum ="


Jul 23 '05 #3

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

Similar topics

3
by: Steven Burn | last post by:
The application; Service on my webserver that allows a user to upload their HOSTS file for functions to verify the contents are still valid. Uses; 1. XMLHTTP (MSXML2) 2. FileSystemObject...
6
by: Foxy Kav | last post by:
Hi, another question from me again, i was just wondering if anyone could give me a quick example of reading data from a file then placing the data into an array for some manipulation then reading...
6
by: Hans Kamp | last post by:
Is it possible to write a function like the following: string ReadURL(string URL) { .... } The purpose is that it reads the URL (determined by the parameter) and returns the string in which...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
8
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
2
by: totoro2468 | last post by:
Here is my code and output. Why is it writing to the array incorrectly, when I rewinded the file to the beginning? CODE: void ReadString (char *filename, int *lengthPtr) { FILE *ifp; char...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
8
by: K Viltersten | last post by:
I'm using XDocument document = XDocument.Load (XmlReader.Create (file)); to load in contents of a XML-file for parsing. However, i noticed that the file seems to be locked by the process and i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...

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.