Is it possible to use cout<< on an array? if not (or if it is easier) how else could i print the entire contents of an array on one line? like
Code:cin >> anArray; cout << anArray;
Is it possible to use cout<< on an array? if not (or if it is easier) how else could i print the entire contents of an array on one line? like
Code:cin >> anArray; cout << anArray;
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
Quzah.Code:for( int x = 0; x < ARRAYCOUNT; x++ ) cout << array[x] << endl;
Hope is the first step on the road to disappointment.
Arrays are no fun, use a vector and do this:
copy ( array.begin(), array.end(), ostream_iterator</* Vector type */> ( cout ) );
-Prelude
My best code is written with the delete key.
i am clueless on vectors. Know any good tutorials?
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
vector.h, I believe, is a class that makes your life easier when using vectors,strings,and such.
search result list from google.com
http://www.google.com/search?hl=en&i...tor.h+tutorial
best search result I could find from the first page results of the search
http://www.cs.brown.edu/people/jak/p...tltut/tut.html
think only with code.
write only with source.
I think that tutorial is very old. The standard says vector (and the whole standard library for that matter), and are in namespace std.
The tutorial hosted by this very site is at least standard in it's conventions.
http://www.cprogramming.com/tutorial/stl/vector.html
Any reference containing information about the STL (Standard Template Library) will get you squared away on "containers", "algorithms" and "iterators".
A standard array is, in fact, a container. A vector is an array (container) with "smart" memory management going for it.
Where a typical array is predefined in size, a vector can expand/collapse as data is added/deleted. (Why didn't you find out about this earlier, right? Hence, Prelude's suggestion.)
Her example code, in a nutshell, is to start with the first element (begin()) of the vector (array) and 'cout' each element up to, and including, the last element (end()).
Oh, what about 'ostream_iterator</* Vector type */>'? The iterator, here, is 'cout' (the standard ouput iterator) and the Vector type is whatever data-type you declare, i.e. int, char, string, etc.
Last thing. What's with "copy"? Well, we don't have to literally copy our vector to another 'container'. In this case, we send our "copy" to the standard output device, the screen.
Note: toaster and SilentStrike have included a couple of links. Cool.
Okay, pick a specific subject area, where we should all know what's going on, that generates much more confusion than standard arrays. How can this not be "fun"? (I'm speaking rhetorically, so, please, take it as such.)Originally posted by Prelude
Arrays are no fun,...
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow