Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > copy an istringstream

Reply
Thread Tools

copy an istringstream

 
 
dover
Guest
Posts: n/a
 
      07-07-2004
/*Copy the line a token at a time into the output*/
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
ostream_iterator<string>(oss, " "));

What's the meaning of this statement? Thanks!



 
Reply With Quote
 
 
 
 
Sharad Kala
Guest
Posts: n/a
 
      07-07-2004

"dover" <(E-Mail Removed)> wrote in message
news:g1OGc.207220$(E-Mail Removed)...
> /*Copy the line a token at a time into the output*/
> copy(istream_iterator<string>(iss),
> istream_iterator<string>(),
> ostream_iterator<string>(oss, " "));
>
> What's the meaning of this statement? Thanks!


Again as your previous post the comment gives you the answer. copy algorithm
takes three parameters - the first two are beginning and one past the end
iterators of the source range and the third parameter is the beginning
iterator of the destination range.
So your source range is a istringstream (strings can behave as external
devices to streams.) Your destination is an ostringstream with space as the
delimiter.
So if input stream contains "This is a test" then destination string will
also contain "This is a test".

-Sharad


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      07-07-2004
dover wrote:

> /*Copy the line a token at a time into the output*/
> copy(istream_iterator<string>(iss),
> istream_iterator<string>(),
> ostream_iterator<string>(oss, " "));
>
> What's the meaning of this statement? Thanks!


It copies the line a token at a time into the output.

 
Reply With Quote
 
Russell Hanneken
Guest
Posts: n/a
 
      07-07-2004
dover wrote:
> /*Copy the line a token at a time into the output*/
> copy(istream_iterator<string>(iss),
> istream_iterator<string>(),
> ostream_iterator<string>(oss, " "));
>
> What's the meaning of this statement? Thanks!


Others have answered this question. I'd like to pose a bonus question
to the group: what's the meaning of this statement?

vector<string> vec( istream_iterator<string>(iss),
istream_iterator<string>() );

--
Russell Hanneken
http://www.velocityreviews.com/forums/(E-Mail Removed)
Use ROT13 to decode my email address.
 
Reply With Quote
 
Sharad Kala
Guest
Posts: n/a
 
      07-08-2004

"Russell Hanneken" <(E-Mail Removed)> wrote in message
news:_jWGc.7781$(E-Mail Removed) ink.net...
> dover wrote:
> > /*Copy the line a token at a time into the output*/
> > copy(istream_iterator<string>(iss),
> > istream_iterator<string>(),
> > ostream_iterator<string>(oss, " "));
> >
> > What's the meaning of this statement? Thanks!

>
> Others have answered this question. I'd like to pose a bonus question
> to the group: what's the meaning of this statement?
>
> vector<string> vec( istream_iterator<string>(iss),
> istream_iterator<string>() );


C++'s most vexing parse! It's a function declaration and not that of a
vector. To get correct results put another set of parenthesis -
vector<string> vec( (istream_iterator<string>(iss)),
istream_iterator<string>() );

Seems you have read Effective STL

-Sharad



 
Reply With Quote
 
Sharad Kala
Guest
Posts: n/a
 
      07-08-2004

"Russell Hanneken" <(E-Mail Removed)> wrote in message
news:_jWGc.7781$(E-Mail Removed) ink.net...
> dover wrote:
> > /*Copy the line a token at a time into the output*/
> > copy(istream_iterator<string>(iss),
> > istream_iterator<string>(),
> > ostream_iterator<string>(oss, " "));
> >
> > What's the meaning of this statement? Thanks!

>
> Others have answered this question. I'd like to pose a bonus question
> to the group: what's the meaning of this statement?
>
> vector<string> vec( istream_iterator<string>(iss),
> istream_iterator<string>() );


C++'s most vexing parse! It's a function declaration and not that of a
vector. To get correct results put another set of parenthesis -
vector<string> vec( (istream_iterator<string>(iss)),
istream_iterator<string>() );

Seems you have read Effective STL

-Sharad





 
Reply With Quote
 
Russell Hanneken
Guest
Posts: n/a
 
      07-08-2004
Sharad Kala wrote:
> "Russell Hanneken" <(E-Mail Removed)> wrote in message
> news:_jWGc.7781$(E-Mail Removed) ink.net...
>
>>I'd like to pose a bonus question
>>to the group: what's the meaning of this statement?
>>
>> vector<string> vec( istream_iterator<string>(iss),
>> istream_iterator<string>() );

>
> C++'s most vexing parse! It's a function declaration and not that of a
> vector. To get correct results put another set of parenthesis -
> vector<string> vec( (istream_iterator<string>(iss)),
> istream_iterator<string>() );
>
> Seems you have read Effective STL


Aw, you got it right. That's no fun. :^)

I haven't actually read _Effective STL_, but I did read "Guru of the
Week" #75, which covers the issue:

http://www.gotw.ca/gotw/075.htm

If anyone's confused about why the statement above declares a function
rather than a vector, I recommend the article.

--
Russell Hanneken
(E-Mail Removed)
Use ROT13 to decode my email address.
 
Reply With Quote
 
Alex Vinokur
Guest
Posts: n/a
 
      07-08-2004

"Sharad Kala" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>
> "Russell Hanneken" <(E-Mail Removed)> wrote in message
> news:_jWGc.7781$(E-Mail Removed) ink.net...
> > dover wrote:
> > > /*Copy the line a token at a time into the output*/
> > > copy(istream_iterator<string>(iss),
> > > istream_iterator<string>(),
> > > ostream_iterator<string>(oss, " "));
> > >
> > > What's the meaning of this statement? Thanks!

> >
> > Others have answered this question. I'd like to pose a bonus question
> > to the group: what's the meaning of this statement?
> >
> > vector<string> vec( istream_iterator<string>(iss),
> > istream_iterator<string>() );

>
> C++'s most vexing parse! It's a function declaration and not that of a vector.


Is it really a function _declaration_? : iss is not type, but variable (istringstream iss).

> To get correct results put another set of parenthesis -
> vector<string> vec( (istream_iterator<string>(iss)),
> istream_iterator<string>() );

[snip]


--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn



 
Reply With Quote
 
Sharad Kala
Guest
Posts: n/a
 
      07-08-2004

"Alex Vinokur" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Sharad Kala" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed)...
> >
> > "Russell Hanneken" <(E-Mail Removed)> wrote in message
> > news:_jWGc.7781$(E-Mail Removed) ink.net...


> Is it really a function _declaration_? : iss is not type, but variable

(istringstream iss).

Yes, it is.

void foo( int d);
void foo (int (d)); // same as above; parens around d are ignored

With this knowledge, in vector<string> vec( istream_iterator<string>(iss),
istream_iterator<string>() );
the first parameter is of type istream_iterator<string>. The parentheses
around iss are superfluous and are ignored. I hope you have got the second
parameter right by yourself

-Sharad


 
Reply With Quote
 
Alex Vinokur
Guest
Posts: n/a
 
      07-08-2004

"Sharad Kala" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
[snip]
>
> void foo( int d);
> void foo (int (d)); // same as above; parens around d are ignored


d is of int type

>
> With this knowledge, in vector<string> vec( istream_iterator<string>(iss),
> istream_iterator<string>() );
> the first parameter is of type istream_iterator<string>. The parentheses
> around iss are superfluous and are ignored.

[snip]

But iss is not of istream_iterator<string> type; iss is of istringstream type.


--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is Deep Copy, shallow copy and bitwises copy.? saxenavaibhav17@gmail.com C++ 26 09-01-2006 09:37 PM
Avoiding copy: char* -> istringstream mathieu C++ 7 07-24-2006 07:03 PM
is dict.copy() a deep copy or a shallow copy Alex Python 2 09-05-2005 07:01 AM
istringstream to bool Agent Mulder C++ 8 08-23-2003 11:55 PM
Allocating istringstream objects Samuele Armondi C++ 1 07-11-2003 10:22 PM



Advertisments