Advertisement Jump to content
Sign in to follow this  

Displaying contents of an array

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

If you intended to correct an error in the post then please contact us.

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.


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 this post

Link to post
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 this post

Link to post
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..

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!