Copy from stream to vector
Hi all, I've started to use boost 1 month ago and I'm findind it very helpful indeed. Congratulations for the good job. I have one question, is it possible to use boost to copy from a stream to a container? If so, how do I? eg. with std copy: copy( istream_iterator<string>(FileSource), istream_iterator<FileSource> (), back_inserter( m_StringVector ) ) I wonder if boost copy would make it simpler, but I was not able to use it. It pops up a static assertion failure :( Any help? Thanks. Ricardo
Which boost copy do you mean? In which particular library is it?
With Kind Regards,
Ovanes
On 10/25/07, Ricardo Mayerhofer
Hi all, I've started to use boost 1 month ago and I'm findind it very helpful indeed. Congratulations for the good job.
I have one question, is it possible to use boost to copy from a stream to a container? If so, how do I?
eg. with std copy: copy( istream_iterator<string>(FileSource), istream_iterator<FileSource> (), back_inserter( m_StringVector ) )
I wonder if boost copy would make it simpler, but I was not able to use it. It pops up a static assertion failure :(
Any help? Thanks.
Ricardo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
That copy writes from a Source to a Sink. Do you need a vector of Strings? Why not a StringStream. You might be able to use your copy on a FileSource and copy to a StringStream. Also your istream_iterator types look inconsistent. mike On Thu, 2007-10-25 at 09:11 -0700, Ricardo Mayerhofer wrote:
I mean copy of boost iostream: http://www.boost.org/libs/iostreams/doc/index.html
Ricardo
If so, how do I?
eg. with std copy: copy( istream_iterator<string>(FileSource), istream_iterator<FileSource> (), back_inserter( m_StringVector ) )
Ricardo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
____________________________________________________________________
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ops, sorry Michael, the example was inconsistent, the correct code is: copy( istream_iterator<string>(FileSource), istream_iterator<string> (), back_inserter( m_StringVector ) ) Actually the class I use is not string, I just though it would make the example simpler. I use another streamable class which I save to a file and retrieve it later. (I cannot use serialization in this case, because the format matters, I mean, I have to save the class state in CSV format). I tought something like this was possible reading the following topic when the lib was being developed: http://lists.boost.org/Archives/boost/2004/09/71455.php
2. Sources and sinks can be reused in cases where standard streams and stream buffers are either unnecessary or are not the appropriate abstraction. For example, suppose you want to write the concatenation of three files to a string. You can do so like this:
string s; boost::io::copy( concatenate( file_source("file1"), file_source("file2"), file_source("file3") ), back_insert_resource(s) );
Thanks. Michael Linck escreveu:
That copy writes from a Source to a Sink. Do you need a vector of Strings? Why not a StringStream. You might be able to use your copy on a FileSource and copy to a StringStream. Also your istream_iterator types look inconsistent.
mike
On Thu, 2007-10-25 at 09:11 -0700, Ricardo Mayerhofer wrote:
I mean copy of boost iostream: http://www.boost.org/libs/iostreams/doc/index.html
Ricardo
If so, how do I?
eg. with std copy: copy( istream_iterator<string>(FileSource), istream_iterator<FileSource> (), back_inserter( m_StringVector ) )
Ricardo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
____________________________________________________________________
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
You might be using the wrong copy. From the STL documentation it looks like std::copy might do exactly what you want: "vector<int> V; copy(istream_iterator<int>(cin), istream_iterator<int>(), back_inserter(V));" from: http://www.sgi.com/tech/stl/istream_iterator.html good luck, mike On Tue, 2007-10-30 at 11:45 -0700, Ricardo Mayerhofer wrote:
Ops, sorry Michael, the example was inconsistent, the correct code is: copy( istream_iterator<string>(FileSource), istream_iterator<string> (), back_inserter( m_StringVector ) )
Actually the class I use is not string, I just though it would make the example simpler. I use another streamable class which I save to a file and retrieve it later. (I cannot use serialization in this case, because the format matters, I mean, I have to save the class state in CSV format).
I tought something like this was possible reading the following topic when the lib was being developed:
http://lists.boost.org/Archives/boost/2004/09/71455.php
2. Sources and sinks can be reused in cases where standard streams and stream buffers are either unnecessary or are not the appropriate abstraction. For example, suppose you want to write the concatenation of three files to a string. You can do so like this:
string s; boost::io::copy( concatenate( file_source("file1"), file_source("file2"), file_source("file3") ), back_insert_resource(s) );
Thanks.
Michael Linck escreveu:
That copy writes from a Source to a Sink. Do you need a vector of Strings? Why not a StringStream. You might be able to use your copy on a FileSource and copy to a StringStream. Also your istream_iterator types look inconsistent.
mike
On Thu, 2007-10-25 at 09:11 -0700, Ricardo Mayerhofer wrote:
I mean copy of boost iostream: http://www.boost.org/libs/iostreams/doc/index.html
Ricardo
If so, how do I?
eg. with std copy: copy( istream_iterator<string>(FileSource), istream_iterator<FileSource> (), back_inserter( m_StringVector ) )
Ricardo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
____________________________________________________________________
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi On Tue, Oct 30, 2007 at 06:46:47PM -0600, Michael Linck wrote:
You might be using the wrong copy. From the STL documentation it looks like std::copy might do exactly what you want:
this mail is not only related to Michael but also other users of this list: LERN PROPERLY QUOTING!
"vector<int> V; copy(istream_iterator<int>(cin), istream_iterator<int>(), back_inserter(V));"
Michael, it seems you do not respond to any quote as all your text is above. Why the hell to you not drop the following text? Boost lists are for subscribers only. To subscribe you have nearly always to read http://www.boost.org/more/discussion_policy.htm (links from http://www.boost.org/more/mailing_lists.htm). Did you forget about all guidelines (which are bt obvious and also true for nearly all other lists and also newsgroups, forums, ...). Even if this is the first and only mailing list you ever used I wonder about this very unusual quoting style ... This also affects:
On Tue, 2007-10-30 at 11:45 -0700, Ricardo Mayerhofer wrote:
and
Michael Linck escreveu:
Very funny:
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
____________________________________________________________________
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ah, thanks for providing this information! It is really so important that it never should be removed from a quoted mail, right? NO! Shame on you! Jens
Jens, I appreciate your advice. Thank you for reminding me of the "rules." You have a valid point that I could have left a particular snippet of the original post to make clear what I was referring to, since the subject line apparently wasn't enough, and I do remember reading about quoting style in the guidelines. I would use "response" type quoting, underneath the text being responded to whenever I find a way to actually make contextual sense out of it. In this case, I guess I decided it was less convenient. To address some other points:
LERN PROPERLY QUOTING!
"vector<int> V; copy(istream_iterator<int>(cin), istream_iterator<int>(), back_inserter(V));"
as far as I know the actual point behind "quoting" in this context is merely not to claim credit for some part of a piece of writing. As I attributed the quote to the website where it originated, I believe that purpose has been served.
Michael, it seems you do not respond to any quote as all your text is above. Why the hell to you not drop the following text?
True, but I was responding to a long string of e-mails in which no-one else seemed to get involved in. I was also trying to point out that an issue that the original poster was having was probably not related to boost.
Boost lists are for subscribers only. To subscribe you have nearly always to read http://www.boost.org/more/discussion_policy.htm (links from http://www.boost.org/more/mailing_lists.htm). Did you forget about all guidelines (which are bt obvious and also true for nearly all other lists and also newsgroups, forums, ...).
Noted. I did not really forget, as mentioned above. The minimal effective amount of quoting from the sender seemed, to me, to be the subject line.
Even if this is the first and only mailing list you ever used I wonder about this very unusual quoting style ...
Why should there only be one way to quote another's e-mail, much less to quote something from a website? I'm sorry if you didn't get the context of the discussion, but as I explained, in that particular post I was merely pointing out that the problem being discussed in the thread probably wasn't a boost issue. I didn't see any reason to quote the actual problem in the thread. As for the following
This also affects:
On Tue, 2007-10-30 at 11:45 -0700, Ricardo Mayerhofer wrote:
... you got me. I was too lazy to delete it because I figured people would get what was going on there and stop reading anyway, so I wasn't really wasting anyone's time by not wasting my own. Since you like the standards, I'd like to point out one final thing: "In addition to technical skills, Boost members value collaboration, acknowledgement of the help of others, and a certain level of politeness." -- http://www.boost.org/more/discussion_policy.htm I think your use of profanity violates this rule, which I find pretty important. This is, in fact, the only e-mail list I've ever participated in. I'm a very hands on learner and I figured the fastest way to get better at using boost was to start listening in on the e-mail list. Occasionally I read something that I feel I might, humbly, be able to contribute a thought to. I apologize if it's taking me a while to get used to the exact format you're looking for, but I think you could have taken a better, less confrontational, and equally effective tack on pointing out that I need to pay more attention to it. thanks anyway, mike
Hi Michael, On Fri, Nov 09, 2007 at 06:38:53PM -0700, Michael Linck wrote:
Jens, I appreciate your advice. Thank you for reminding me of the "rules." You have a valid point that I could have left a particular
thanks. Please note that I did not just addressed you but all people which ignore the mailinglist rules and quote in an obscure way. I hope these people profit from this mail as well.
Boost lists are for subscribers only. To subscribe you have nearly always to read http://www.boost.org/more/discussion_policy.htm (links from http://www.boost.org/more/mailing_lists.htm). Did you forget about all guidelines (which are bt obvious and also true for nearly all other lists and also newsgroups, forums, ...).
[Let's not drop this from the mail so that other find it more easily.]
Why should there only be one way to quote another's e-mail, much less to quote something from a website? I'm sorry if you didn't get the context
Indeed there may be some other possibilities. There are no very strict rules but I have seen top posting in this thread (and in others) for a too long time. The mail grew and was already very long. Nobody tried to truncate it ... Top posting e.g. just reverses the replies and is bad:
Fine
Will do
Please quote properly
... you got me. I was too lazy to delete it because I figured people would get what was going on there and stop reading anyway, so I wasn't really wasting anyone's time by not wasting my own.
I prefer to stop reading at the bottom of the mail so it would be nice to see only short emails on lists :-)
Since you like the standards, I'd like to point out one final thing:
"In addition to technical skills, Boost members value collaboration, acknowledgement of the help of others, and a certain level of politeness." -- http://www.boost.org/more/discussion_policy.htm
I think your use of profanity violates this rule, which I find pretty important.
Maybe. I will try my best to improve it. Jens
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ah, thanks for providing this information! It is really so important
Jens said: that
it never should be removed from a quoted mail, right? NO!
I don't know anything about how news lists are administered, but how difficult would it be for boost to have an automatic rule that bounces emails which quote the footer? Or emails with nothing but whitespace after the last '>'? I think most guilty parties are infrequent or new list users who would appreciate the private reminder rather than have inadvertent rudeness as a matter of public record (whether somebody complains or not). -- John
participants (5)
-
Jens Seidel
-
John Femiani
-
Michael Linck
-
Ovanes Markarian
-
Ricardo Mayerhofer