Connecting Tech Pros Worldwide Forums | Help | Site Map

Perl split() function equivalent in C++

Susan Baker
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi,

I'm working on s simple parser and I would like to split up multi-line
expressions into single expressions. Is there a way whereby I could
slurp the lines into an array (or other container)?

The perl equivalent way of doing this is with the split function. Is
there an equivalent in C++ - or do I have to roll my own tokenizer?


Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Perl split() function equivalent in C++


Susan Baker wrote:[color=blue]
> [..]
> The perl equivalent way of doing this is with the split function. Is
> there an equivalent in C++ - or do I have to roll my own tokenizer?[/color]

There is no equivalent. You need to roll your own.
Susan Baker
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Perl split() function equivalent in C++




Victor Bazarov wrote:
[color=blue]
> Susan Baker wrote:
>[color=green]
>> [..]
>> The perl equivalent way of doing this is with the split function. Is
>> there an equivalent in C++ - or do I have to roll my own tokenizer?[/color]
>
>
> There is no equivalent. You need to roll your own.[/color]

Thanks - actually, I just did whilst I was waiting for a response.
Apologies.

msalters
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Perl split() function equivalent in C++




Susan Baker schreef:[color=blue]
> Hi,
>
> I'm working on s simple parser and I would like to split up multi-line
> expressions into single expressions. Is there a way whereby I could
> slurp the lines into an array (or other container)?[/color]

Yes. Asssuming the lines are in a std::istream& of some sort
(which includes std::stringstream), turn the lines into a container
with std::istream_iterator. You might need to add a Line class if
you don't have yet.

After that, it's just a std::copy( )

HTH,
Michiel Salters

ashim.seth@gmail.com
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Perl split() function equivalent in C++


hey try using a stack had made a parsin table myself
it helped

Closed Thread