Topic: STL Examples -- where are they?
Author: pete@borland.com (Pete Becker)
Date: Mon, 13 Mar 95 17:37:33 PST Raw View
In article <3jt2lr$qae@jupiter.SJSU.EDU>, horstman@sjsumcs.sjsu.edu says...
>
>Ok, I took pity on the people who want to see STL examples. Here are two
>examples of a Hello, World program in STL. Enjoy!
>
Here's a third:
int main( int argc, char *argv[] )
{
copy( argv, argv+argc, ostream_iterator<char *>(cout, "\n"));
return 0;
}
It copies each of its input parameters onto a separate line on standard out. Without
STL you'd write something like this:
int main( int argc, char *argv[] )
{
for( int i = 0; i < argc; ++i )
cout << argv[i] << "\n";
return 0;
}
In simple programs like these it may well appear that the non-STL version is
simpler. The big advantage that STL has is that it generalizes cleanly:
int main( int argc, char *argv[] )
{
vector<char *> vect;
copy( argv, argv+argc, inserter(vect) );
copy( vect.begin(), vect.end(), ostream_iterator<char *>(cout,"\n"));
return 0;
}
-- Pete
Author: holder@alsys.com (Robert L. Holder @ignite)
Date: Wed, 15 Mar 1995 00:11:42 GMT Raw View
In <JAD.95Mar10164100@pimlico.hpl.hp.com> jad@pimlico.hpl.hp.com (John Dilley) writes:
>> Where can I find examples of code using the STL? I have looked
>> in the _very_ limited places I know to look. BTW, what is the
>> official site for the STL stuff anyway?
Ch 5 of the STL Reference manual contains some simple example
programs. This can be obtained from the site
ftp://butler.hpl.hp.com/stl
Author: horstman@sjsumcs.sjsu.edu (Cay Horstmann)
Date: 11 Mar 1995 20:54:19 GMT Raw View
Ok, I took pity on the people who want to see STL examples. Here are two
examples of a Hello, World program in STL. Enjoy!
int main()
{ copy(istream_iterator<char>(istrstream("Hello, World\n")),
istream_iterator<char>(),
ostream_iterator<char>(cout));
return 0;
}
If your compiler doesn't support default template arguments, use
istream_iterator<char, ptrdiff_t> instead.
int main()
{ char h[] = "Hello, World\n";
for_each(h, h + sizeof(h), bind2nd(ptr_fun(fputc), stdout));
return 0;
}
The second example would be nicer if one could somehow use cout and
left_shift<ostream, char>, but there are technical differences due to
the fact that ostream_with_assign has no copy constructor. I was tempted
to define a class ostream_with_assign_and_copy_construction to solve that
problem, but I'll leave that for the obfuscated C++ contest.
Cay
horstman@cs.sjsu.edu
Author: allen@wuerl.wustl.edu (Allen Rueter)
Date: 12 Mar 1995 21:45:01 -0600 Raw View
In article <JAD.95Mar10164100@pimlico.hpl.hp.com>,
John Dilley <jad@pimlico.hpl.hp.com> wrote:
>
> - you can buy a supported, documented version from ObjectSpace
> (Dallas, TX; I don't have their contact information).
>
The pen I have from there class says 1-800-object1
allen@mir.wustl.edu
Author: horstman@sjsumcs.sjsu.edu (Cay Horstmann)
Date: 10 Mar 1995 18:08:34 GMT Raw View
Mike Beard (75113.3031@CompuServe.COM) wrote:
: Where can I find examples of code using the STL? I have looked
: in the _very_ limited places I know to look. BTW, what is the
: official site for the STL stuff anyway?
: Thanks in advance for the help.
: Mike
Let me say that I have NO relationship whatsoever with the outfit I am
about to recommend... I found Modena's STL adaptation a good source of
example code and tutorial information. They charge, I believe, $99. If
you are not amused by the Stepanov/Lee documentation, you may like Modena.
As always, it is a time vs. money tradeoff. Their email address is
modena@netcom.com
Cay
horstman@cs.sjsu.edu
Author: jad@pimlico.hpl.hp.com (John Dilley)
Date: Fri, 10 Mar 1995 23:41:00 GMT Raw View
In article <3jlun0$p42$1@mhadf.production.compuserve.com> Mike Beard <75113.3031@CompuServe.COM> writes:
> Where can I find examples of code using the STL? I have looked
> in the _very_ limited places I know to look. BTW, what is the
> official site for the STL stuff anyway?
I don't know where you can find code examples, but:
- you can get STL from /ftp@butler.hpl.hp.com:/stl or
- you can buy a supported, documented version from ObjectSpace
(Dallas, TX; I don't have their contact information).
Regards,
-- jad --
Author: Mike Beard <75113.3031@CompuServe.COM>
Date: 9 Mar 1995 04:03:44 GMT Raw View
Where can I find examples of code using the STL? I have looked
in the _very_ limited places I know to look. BTW, what is the
official site for the STL stuff anyway?
Thanks in advance for the help.
Mike
--
=============
Mike Beard