Perl split() function equivalent in C++

S

Susan Baker

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?
 
V

Victor Bazarov

Susan said:
[..]
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?

There is no equivalent. You need to roll your own.
 
S

Susan Baker

Victor said:
Susan said:
[..]
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?


There is no equivalent. You need to roll your own.

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

msalters

Susan Baker schreef:
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)?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,335
Latest member
Tommiesal

Latest Threads

Top