473,465 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C++ I/O for parsing a simple file

Hello!

I'd be very grateful if you can give some advice to me. I explain my
problem:

I want to read a file whose structure I need to be like this:

#comments...
value1,value2,value3,...,valueN # comments...
#comments...
value1,value2,value3,...,valueN # comments...
....
value1,value2,value3,...,valueN # comments...

So what I want is to be able to read a file in which there are some
lists of values separated by new line. Each value is separated by a
comma. And there may be comments at the beggining or at the end of any line.

I can't use getline(...,...,'\n') because I have to take care of '#'
I can't use getline(...,...,'\#') because comments are not compulsory.

So what do you suggest?

thanks.
Jul 23 '05 #1
4 1484
Val
|
| I can't use getline(...,...,'\n') because I have to take care of '#'
| I can't use getline(...,...,'\#') because comments are not compulsory.
|

Yes you can. Then check for the existance of "#". It it exists, remove it and everything that comes after that.
Jul 23 '05 #2
Nafai wrote:
Hello!

I'd be very grateful if you can give some advice to me. I explain my
problem:

I want to read a file whose structure I need to be like this:

#comments...
value1,value2,value3,...,valueN # comments...
#comments...
value1,value2,value3,...,valueN # comments...
...
value1,value2,value3,...,valueN # comments...

So what I want is to be able to read a file in which there are some
lists of values separated by new line. Each value is separated by a
comma. And there may be comments at the beggining or at the end of any
line.

I can't use getline(...,...,'\n') because I have to take care of '#'
I can't use getline(...,...,'\#') because comments are not compulsory.

So what do you suggest?

thanks.


I would use an fstream and read a line at a time (so basically the
getline()). Then I would check the first character, if it's a # then the
line is a comment. If not, the the line contains values a possible comment.
How you handle when a line doesn't start with a # can be done 101 different
ways.
Jul 23 '05 #3
I asked this question because there are many files with this structure
and I thought there would be a "standard" way of doing sth like this. I
can do it my way but I would like to hear some tips or frequent ways of
doing this.

Thanks.
Alvin Beach escribió:
Nafai wrote:

Hello!

I'd be very grateful if you can give some advice to me. I explain my
problem:

I want to read a file whose structure I need to be like this:

#comments...
value1,value2,value3,...,valueN # comments...
#comments...
value1,value2,value3,...,valueN # comments...
...
value1,value2,value3,...,valueN # comments...

So what I want is to be able to read a file in which there are some
lists of values separated by new line. Each value is separated by a
comma. And there may be comments at the beggining or at the end of any
line.

I can't use getline(...,...,'\n') because I have to take care of '#'
I can't use getline(...,...,'\#') because comments are not compulsory.

So what do you suggest?

thanks.

I would use an fstream and read a line at a time (so basically the
getline()). Then I would check the first character, if it's a # then the
line is a comment. If not, the the line contains values a possible comment.
How you handle when a line doesn't start with a # can be done 101 different
ways.

Jul 23 '05 #4
> I would use an fstream and read a line at a time (so basically the
getline()). Then I would check the first character, if it's a # then the
line is a comment. If not, the the line contains values a possible comment.
How you handle when a line doesn't start with a # can be done 101 different
ways.


I asked this question because there are many files with this structure
and I thought there would be a "standard" way of doing sth like this. I
can do it my way but I would like to hear some tips or frequent ways of
doing this.

Thanks.
Jul 23 '05 #5

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

Similar topics

4
by: Gert Van den Eynde | last post by:
Hi all, Could you give me some pointers on how to parse a text input file in C++? Most will be config-file style input (keyword = data), but some maybe 'structures' like material{ name = n,...
3
by: John Doe | last post by:
I've been doing some reading/research on parsing simple configuration files through C, and have heard various opinions on the matter. I'd like to solicit some opinions and design criteria (as well...
2
by: Anthony Boudouvas | last post by:
Hi to all, i have a very simple XML file that i present to a user and i will allow him/her to manualy edit it and send it back to a listening server. What is the best -simple- way to parse it...
1
by: Christoph Bisping | last post by:
Hello! Maybe someone is able to give me a little hint on this: I've written a vb.net app which is mainly an interpreter for specialized CAD/CAM files. These files mainly contain simple movement...
2
by: Jean-Marie Vaneskahian | last post by:
Reading - Parsing Records From An LDAP LDIF File In .Net? I am in need of a .Net class that will allow for the parsing of a LDAP LDIF file. An LDIF file is the standard format for representing...
4
by: Rick Walsh | last post by:
I have an HTML table in the following format: <table> <tr><td>Header 1</td><td>Header 2</td></tr> <tr><td>1</td><td>2</td></tr> <tr><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td></tr>...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
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...
1
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.