![]() |
How to read input with comments led by some commenting symbol
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 |
Re: How to read input with comments led by some commenting symbol
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 |
Re: How to read input with comments led by some commenting symbol
On Nov 14, 10:13*am, Victor Bazarov <v.baza...@comcast.invalid> 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 |
Re: How to read input with comments led by some commenting symbol
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: boost-users@lists.boost.org with a subject starting with [iostreams]. I'd guess you'd get more and possibly better responses than on this list. -regards, Larry |
Re: How to read input with comments led by some commenting symbol
On Nov 14, 10:54*am, Larry Evans <cppljev...@suddenlink.net> 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: > > * boost-us...@lists.boost.org > > 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 |
Re: How to read input with comments led by some commenting symbol
On Nov 14, 10:34*am, Jayden Shui <jayden.s...@gmail.com> wrote:
> On Nov 14, 10:13*am, Victor Bazarov <v.baza...@comcast.invalid> 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 |
Re: How to read input with comments led by some commenting symbol
On Mon, 2011-11-14, Jayden Shui wrote:
> On Nov 14, 10:13*am, Victor Bazarov <v.baza...@comcast.invalid> 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 . |
Re: How to read input with comments led by some commenting symbol
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<v.baza...@comcast.invalid> 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 |
Re: How to read input with comments led by some commenting symbol
On Nov 14, 3:12*pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
> On Mon, 2011-11-14, Jayden Shui wrote: > > On Nov 14, 10:13*am, Victor Bazarov <v.baza...@comcast.invalid> 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. |
Re: How to read input with comments led by some commenting symbol
On Mon, 2011-11-14, AnonMail2005@gmail.com wrote:
> On Nov 14, 3:12*pm, Jorgen Grahn <grahn+n...@snipabacken.se> 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 . |
| All times are GMT. The time now is 02:39 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.