reading parameter file and parsing the contents

E

easy

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 =
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890_.,";
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.
 
E

Edernity

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top