Whenever I start my program from the command line, it works perfectly. When I try to use the icon on the desktop, it gets to the last cin statement and terminates. I have no idea why this would happen. Any insight?

Whenever I start my program from the command line, it works perfectly. When I try to use the icon on the desktop, it gets to the last cin statement and terminates. I have no idea why this would happen. Any insight?

Hard to say from that description, but there could be a cin statement, and then the program does whatever it does, and it may execute so fast that it looks like it didn't get past the cin statement, but it in fact did everything it was supposed to. The program was faster than your eye, did whatever was left for it to do, then terminated, at which time the console window that opened when you double clicked the icon closed. When the program is over, the console window will close. Unless you have designed the program to wait for the user to close the console window, that window will close without prompting. This doesn't happen when you run from the command line since the console window was already open, so the program doesn't close it. Here's a link that explains it a little more and offers a way to keep that console window open. There are also some threads on Daniweb. No guarantee that that is what is going on in your particular case, but that's my first guess.
http://www.dreamincode.net/forums/showtopic30581.htm

At the end of the code, try adding

cin.ignore()

Or rather:

#include <limits>

...

int main()
  {
  ...

  cout << "Press Enter to continue...";
  cin.ignore( numeric_limits<streamsize>::max(), '\n' );

  return 0;
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.