File input procedure

I have written a database program, that writes a file so that it can be read by a cgi program. It must also be used by the database program that writes it. It is written in a format, that is easily readable by the cgi quickly, unfortunately, this makes it a bit more difficult for the database to parse the file. Here is an example file, I use c++ comments, to help explain different portions. All important information in the file is preceded by a newline. Here goes. . .
0(55)//0 is the record number, there are 44 records total and the 55 is the line where the next record begins (for the cgi, my database will ignore this)
Page Title//the title my cgi, will display in the window, again my program does not read this
Page specific code//another portion that is not read by my database
Number of internal links//again only for the cgi
{//marks the beginning of where my database program should read into internal links
<LI><A HREF=//ignored by database');>//the url is the first piece of data my database reads.
Title</A>//Database must read the title, and ignore the </A>
Description</LI>//database must read description and ignore </LI>
... more links would follow
}//marks the end of internal links
{//marks the beginning of external links
a line of cgi stuff
url//important to program
Title//important for program
Description//important to program
... more links would follow

1//next record would begin

So the question is basically, how can I read a file in such a way that I can skip unimportant lines and when I get to an important line, skip everything after a certain point.
If I left anything out please say so. This is the last part my program needs and than its done.
I thank you in advance for all of your help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In a sense you can't ignore stuff in the file.  In a unstructured file, like this text file, all the text will have to be read up to any point of interest.  However, you can use functions that read and ignore information while waiting for a certain important peice of information.  For exampel you could ignore everything on a line by reading all the characters on the line and ignoring them until a newline characters is reached.

If you use the fstream class to read the file, which is probably a good idea, you can use the ignore() member function to ignnore data until a particular character (like a newline) is encountered.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Here are some examples to get you started.

fstream Fil("SomeFileName",ios_base::in);
int RecNum
int RecCnt;
string Title;

Fil >> RecNum; // Read record number
Fil.ignore(1); // Ignore the "{".
Fil >> RecCnt; // Read record  count.
Fil.ignore(numeric_limits<int>::max(),'\n'); // Ignore until the end of the line.
getline(Fil,Title); // Read whole title line.

Let me know if you have any questions.
rkcthAuthor Commented:
How can I ignore data after a certain character, with the C++ input classes. I was using the C classes, because the C++ ones seem a bit more difficult. They are so easy for output, perhaps I don't understand them well enough. If I can work it out with your information, I'll be sure to give you the points. I noticed you give information all over the boards and would like to thank you. You have helped me with several other problems if I remember correctly:)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

rkcthAuthor Commented:
I have not heard of numeric_limits<int>::max() and could not find it in my references
>> the C++ ones seem a bit more difficult.
They might be a little strange at first, but they are much much easier to use.  They have so many powerful features that the C ones done.  Plus they are type safe.

numeric_limits<> is defined in the <limits> include file.  Just include <limits> and you should be fine.  The templates inside define the mathematical ranges and other properties of the basic numeric types.
>> How can I ignore data after a certain character
I guess there are two issues in this.  First you need to read data up to that character, then you read and ignore data from there on up to some other point, probably the end of the line.

Exactly how you do that will depend in the nature of the data to be read, the delimiting character for that data, and delimiting character for the data to be ignored.  But for example, if you want to read all the data on a line up to an "!", then ignore the rest of the data on the line, you could do.

string Data;

getline(Fil,Data,'!'); // Read up to the "!";
Fil.ignore(numeric_limits<int>::max(),'\n'); // Ignore the rest of the line.

If the '!' doesn't always appear on the line you might have to take a different approach, like read the whole line into the string, then search for the "!" in the string and remove it and what follows it if found.

If the data before the "!" is numeric instead of a string, you might use a different technique to read it.  

As you can see there are lots of possiblilities, it depends on the exact details of what you want to do.
rkcthAuthor Commented:
The program is done, thank you nietod. I must say, you give the most concise answers. Within a minute or so of reading your answer, I had it figured out. Within 3 hours the entire project was finished.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.