Jump to content
  • Advertisement
Sign in to follow this  
PsyberMind

Displaying contents of an array

This topic is 2791 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.

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


Link to post
Share on other sites
Advertisement
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!