Re: vector
Andrew Ostry wrote:
std::vector is object of Class vector? vector is a type / c++ object?
std::vector is a class template.
std::copy - is it a function of some header?
It is a function template. It's in <algorithm>. Do you have a copy of
"The C++ Standard Library"? If you don't, run *now* to the nearest
bookstore and *get yourself one*!
Or get yourself any other decent C++ book, there are quite a few to
choose from. What book are you reading that doesn't explain what
'std::vector' or 'std::copy' are?
> which object is it
associate to?
std::copy is a template of a stand-alone function.
> when calling function, do we call it using the dot(.)
or -> reference notation?
It depends on the left-hand side. But for 'std::copy' you don't need
any, it's a stand-alone function template.
#include <iostream>
using std::cout;
using std::endl;
#include <algorithm> // algorithm definitions
#include <vector> // vector class-template definition
#include <iterator> // ostream_iterator
int main()
{
const int SIZE = 10;
int a1[ SIZE ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int a2[ SIZE ] = { 1, 2, 3, 4, 1000, 6, 7, 8, 9, 10 };
std::vector< int > v1( a1, a1 + SIZE ); // copy of a1
std::vector< int > v2( a1, a1 + SIZE ); // copy of a1
std::vector< int > v3( a2, a2 + SIZE ); // copy of a2
std::ostream_iterator< int > output( cout, " " );
cout << "Vector v1 contains: ";
std::copy( v1.begin(), v1.end(), output );
cout << "\nVector v2 contains: ";
std::copy( v2.begin(), v2.end(), output );
cout << "\nVector v3 contains: ";
std::copy( v3.begin(), v3.end(), output );
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask