# Displaying contents of an array

This topic is 2704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is really fundamental stuff, and the code is right, that I can see. But, being new to C++ I thought I'd throw this in here to see if I missed something.

Snippit:

int list[] = {7, 3, 32, 2, 55, 34, 6, 13, 29, 22, 11, 9, 1};cout << "The list of numbers is: ";		for (int x=0; x > 17; ++x)	{		 cout << list[x] << ", ";	}	cout << endl;

It compiles, and runs, but list[x] doesn't display. I know I'm missing something simple.

##### Share on other sites
Your condition is "x > 17". But x starts at 0, which is not greater than 17. So the loop never executes.

You might consider using std::copy algorithm:
#include <algorithm>#include <iterator>std::copy(list, list + 17, std::ostream_iterator<int>(std::cout, ", "));

##### Share on other sites
I knew it was something simple too, dangit.. changed to < and worked like a charm.

As far as the algorithm.. I'm not quite there yet, still getting the basics down, then will move on to the harder stuff.. I'm actually following a text book (a slightly older one) that a friend of mine sent me from his college days, pending Amazon's delivery of my Xmas present..

• 22
• 10
• 19
• 14
• 20