Boost logo

Boost Users :

From: Tommy Li (tommycli_at_[hidden])
Date: 2006-08-03 21:26:55


John Maddock wrote:
> Tommy Li wrote:
>>> I think I'm missing something obvious. Anyone have any idea?
>> By the way, I can't even match one newline char with "\\n" though they
>> are obviously there.
>
> Well here's a sample program that obviously shows it does work :-)
>
> #include <boost/regex.hpp>
> #include <iostream>
>
> int main(int,char**)
> {
> boost::regex e("\\n");
> std::string s("one\ntwo\nthree");
> boost::sregex_token_iterator i(s.begin(), s.end(), e, -1), j;
> while(i != j)
> {
> std::cout << "<" << *i << ">" << std::endl;
> ++i;
> }
> }
>
> which outputs:
>
> <one>
> <two>
> <three>
>
> Just as expected.
>
> John.

Great. Thanks a ton. The problem I was having was that I was using
getline to read from stdin, which stripped the newlines (duh). Changing
it to while(!cin.eof()) input.append(1, cin.get()); fixed it.

By the way, do you have a better way of reading the entire stream,
including newlines, into a string?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net