Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to read input with comments led by some commenting symbol

Reply
Thread Tools

How to read input with comments led by some commenting symbol

 
 
Jayden Shui
Guest
Posts: n/a
 
      11-14-2011
Hello All,

I am thinking about using streams to read input with comments led by
some commenting symbol such as '#'. I appreciate your suggestion.

Best regards,

Jayden
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-14-2011
On 11/14/2011 10:01 AM, Jayden Shui wrote:
> I am thinking about using streams to read input with comments led by
> some commenting symbol such as '#'. I appreciate your suggestion.


I suggest you get on with it, then.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
Jayden Shui
Guest
Posts: n/a
 
      11-14-2011
On Nov 14, 10:13*am, Victor Bazarov <(E-Mail Removed)> wrote:
> On 11/14/2011 10:01 AM, Jayden Shui wrote:
>
> > I am thinking about using streams to read input with comments led by
> > some commenting symbol such as '#'. I appreciate your suggestion.

>
> I suggest you get on with it, then.
>
> V
> --
> I do not respond to top-posted replies, please don't ask


I have two methods to do it, but am not satisfied. One is developing a
manipulator ignore_comments and use it like:

cin >> ignore_comments >> data1 >> ignore_comments >> data2 >> ...

The other way is using boost filtering stream shown in

http://www.boost.org/doc/libs/1_47_0...doc/index.html

I tried this method, but when I input by cin, I have to click ctrl+z
twice to stop the input and let the code continue to run. I don' know
why?

Thank you for your help!

Jayden

 
Reply With Quote
 
Larry Evans
Guest
Posts: n/a
 
      11-14-2011
On 11/14/11 09:34, Jayden Shui wrote:
[snip]
> The other way is using boost filtering stream shown in
>
> http://www.boost.org/doc/libs/1_47_0...doc/index.html
>
> I tried this method, but when I input by cin, I have to click ctrl+z
> twice to stop the input and let the code continue to run. I don' know
> why?


Try posting this question to the boost users list:

http://www.velocityreviews.com/forums/(E-Mail Removed)

with a subject starting with [iostreams].

I'd guess you'd get more and possibly better responses than on
this list.

-regards,
Larry
 
Reply With Quote
 
Jayden Shui
Guest
Posts: n/a
 
      11-14-2011
On Nov 14, 10:54*am, Larry Evans <(E-Mail Removed)> wrote:
> On 11/14/11 09:34, Jayden Shui wrote:
> [snip]
>
> > The other way is using boost filtering stream shown in

>
> > * *http://www.boost.org/doc/libs/1_47_0...doc/index.html

>
> > I tried this method, but when I input by cin, I have to click ctrl+z
> > twice to stop the input and let the code continue to run. I don' know
> > why?

>
> Try posting this question to the boost users list:
>
> * (E-Mail Removed)
>
> with a subject starting with [iostreams].
>
> I'd guess you'd get more and possibly better responses than on
> this list.
>
> -regards,
> Larry


Thank you very much!

Best regards,

Jayden
 
Reply With Quote
 
AnonMail2005@gmail.com
Guest
Posts: n/a
 
      11-14-2011
On Nov 14, 10:34*am, Jayden Shui <(E-Mail Removed)> wrote:
> On Nov 14, 10:13*am, Victor Bazarov <(E-Mail Removed)> wrote:
>
> > On 11/14/2011 10:01 AM, Jayden Shui wrote:

>
> > > I am thinking about using streams to read input with comments led by
> > > some commenting symbol such as '#'. I appreciate your suggestion.

>
> > I suggest you get on with it, then.

>
> > V
> > --
> > I do not respond to top-posted replies, please don't ask

>
> I have two methods to do it, but am not satisfied. One is developing a
> manipulator ignore_comments and use it like:
>
> * * cin >> ignore_comments >> data1 >> ignore_comments >> data2 >> ....
>
> The other way is using boost filtering stream shown in
>
> * *http://www.boost.org/doc/libs/1_47_0...doc/index.html
>
> I tried this method, but when I input by cin, I have to click ctrl+z
> twice to stop the input and let the code continue to run. I don' know
> why?
>
> Thank you for your help!
>
> Jayden


May I suggest you just write your own getline function? I don't know
your requirements but it seems more straightforward if you're doing
line based input.

There's a C++ library getline function that reads a line into a
std::string. It's very easy to use that inside your own getline
function which just skips comment lines however you define them.

HTH
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-14-2011
On Mon, 2011-11-14, Jayden Shui wrote:
> On Nov 14, 10:13*am, Victor Bazarov <(E-Mail Removed)> wrote:
>> On 11/14/2011 10:01 AM, Jayden Shui wrote:
>>
>> > I am thinking about using streams to read input with comments led by
>> > some commenting symbol such as '#'. I appreciate your suggestion.

>>
>> I suggest you get on with it, then.


> I have two methods to do it, but am not satisfied. One is developing a
> manipulator ignore_comments and use it like:
>
> cin >> ignore_comments >> data1 >> ignore_comments >> data2 >> ...
>
> The other way is using boost filtering stream shown in
>
> http://www.boost.org/doc/libs/1_47_0...doc/index.html


I just do it like I do it in Perl: read line by line, and for each line:
- does it contain a #? Then continue parsing the text between start
of line and the #.
- otherwise, parse the text between start of line and '\n' or
end-of-line

Has been good enough so far.

Never learned to use the fancy iostreams input stuff, and all the
questions about that around here makes me think that was the right
choice!

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      11-14-2011
On 11/14/2011 3:12 PM, Jorgen Grahn wrote:
> On Mon, 2011-11-14, Jayden Shui wrote:
>> On Nov 14, 10:13 am, Victor Bazarov<(E-Mail Removed)> wrote:
>>> On 11/14/2011 10:01 AM, Jayden Shui wrote:
>>>
>>>> I am thinking about using streams to read input with comments led by
>>>> some commenting symbol such as '#'. I appreciate your suggestion.
>>>
>>> I suggest you get on with it, then.

>
>> I have two methods to do it, but am not satisfied. One is developing a
>> manipulator ignore_comments and use it like:
>>
>> cin>> ignore_comments>> data1>> ignore_comments>> data2>> ...
>>
>> The other way is using boost filtering stream shown in
>>
>> http://www.boost.org/doc/libs/1_47_0...doc/index.html

>
> I just do it like I do it in Perl: read line by line, and for each line:
> - does it contain a #? Then continue parsing the text between start
> of line and the #.
> - otherwise, parse the text between start of line and '\n' or
> end-of-line
>
> Has been good enough so far.
>
> Never learned to use the fancy iostreams input stuff, and all the
> questions about that around here makes me think that was the right
> choice!


That should work just fine as long as there are no tokens that are
allowed to contain # that isn't the beginning of a "comment", like
string literals, for instance...

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
AnonMail2005@gmail.com
Guest
Posts: n/a
 
      11-14-2011
On Nov 14, 3:12*pm, Jorgen Grahn <(E-Mail Removed)> wrote:
> On Mon, 2011-11-14, Jayden Shui wrote:
> > On Nov 14, 10:13*am, Victor Bazarov <(E-Mail Removed)> wrote:
> >> On 11/14/2011 10:01 AM, Jayden Shui wrote:

>
> >> > I am thinking about using streams to read input with comments led by
> >> > some commenting symbol such as '#'. I appreciate your suggestion.

>
> >> I suggest you get on with it, then.

> > I have two methods to do it, but am not satisfied. One is developing a
> > manipulator ignore_comments and use it like:

>
> > * * cin >> ignore_comments >> data1 >> ignore_comments >> data2 >> ....

>
> > The other way is using boost filtering stream shown in

>
> > * *http://www.boost.org/doc/libs/1_47_0...doc/index.html

>
> I just do it like I do it in Perl: read line by line, and for each line:
> - does it contain a #? *Then continue parsing the text between start
> * of line and the #.
> - otherwise, parse the text between start of line and '\n' or
> * end-of-line
>
> Has been good enough so far.
>
> Never learned to use the fancy iostreams input stuff, and all the
> questions about that around here makes me think that was the right
> choice!
>
> /Jorgen
>
> --
> * // Jorgen Grahn <grahn@ *Oo *o. * . * * .
> \X/ * * snipabacken.se> * O *o * .


I totally concur with you comment on iostreams. Especially when most
of my work is done reading line by line.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      11-14-2011
On Mon, 2011-11-14, (E-Mail Removed) wrote:
> On Nov 14, 3:12*pm, Jorgen Grahn <(E-Mail Removed)> wrote:

....
>> Never learned to use the fancy iostreams input stuff, and all the
>> questions about that around here makes me think that was the right
>> choice!


> I totally concur with you comment on iostreams. Especially when most
> of my work is done reading line by line.


I should add that I /do/ like them for line-by-line input, and for
formatted output. It's the formatted input I don't like (and I don't
like fscanf() either).

Some reject iostreams entirely.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
(Encryption Package) error: cannot find symbol symbol: class BaseNCode clusardi2k@aol.com Java 6 08-29-2012 08:33 PM
Why ":symbol" failed but 'symbol' successed with JRuby 1.0.3? Song Ma Ruby 2 07-20-2008 04:08 AM
what's differnece between #ifdef symbol and #if defined(symbol) baumann@pan C Programming 1 04-15-2005 08:25 AM
LED there be Light, a D.I.Y. LED ringlight E Pericoloso Sporgersi Digital Photography 18 08-19-2003 03:22 PM



Advertisments