That scares me. Is it an actual For loop or an imitation?
The std::copy function is in the "algorithm" header. To it we pass two iterators. The first iterator is the beginning of the sequence, and the second is the end of the sequence.
Because iterators in C++ use the same operators as array access, we can provide the name of the array (which is actually a pointer to the beginning of the array in memory) as the initial iterator.
Since foo is 5 elements long, "foo + 5" indicates the end of the array. COnsider the following equivalences to better understand this:
code:
*foo == *(foo + 0) == foo[0]
*(foo + 5) == foo[5]
For an array of length 5, the last index is 4. Therefore if we have an index of 5, we are past the end of the array.
The third argument to the std::copy function is the output iterator. For this we use the ostream_iterator class from the "iterator" header. To its constructor we pass the ostream object we want to copy to. In this case, std::cout. We also pass the separator. This is a string that gets output after each element.
Make more sense now?
Sponsor Sponsor
Sanjay
Posted: Tue May 02, 2006 8:46 pm Post subject: (No subject)
Yep, thanks mate.
This is the only real reason I would consider .NET: If I was working with a group of programmers who don't understand:
for(i=1;i<5,i++){cout << i;}
It reads like normal English (Actually, after a night of programming till 5 in the morning, I actually said "cout hello, Alex" to a friend. Maybe reading like English isn't such a good idea..,)
wtd
Posted: Tue May 02, 2006 9:03 pm Post subject: (No subject)
Sanjay wrote:
Yep, thanks mate.
This is the only real reason I would consider .NET: If I was working with a group of programmers who don't understand:
for(i=1;i<5,i++){cout << i;}
If you're working with a group of programmers who cannot understand such simple code (once you fix your typo ) then switching to another language/environment will not save you.
wtd
Posted: Tue May 02, 2006 9:07 pm Post subject: (No subject)