GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Dec-2004, 12:27
NotReallyHere NotReallyHere is offline
New Member
 
Join Date: Dec 2004
Posts: 2
NotReallyHere is on a distinguished road

Can't run any programs I compile, please help


I recently started learning how to code in C++. The problem is, any program I compile doesn't work.
There are no errors in the code whatsoever, and when I debug it step by step, it works until the very end.
When I try to run it, the dos window comes up in a flash and is gone.
I'm using bloodshed dev-c++ version 4.1, and I'm running Windows XP. When I send the files to my friend, he gets the same problem. However, the Java programs that he compiles work fine. Is it a problem with my compiler?
  #2  
Old 29-Dec-2004, 13:34
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,709
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by NotReallyHere
I recently started learning how to code in C++. The problem is, any program I compile doesn't work.
There are no errors in the code whatsoever, and when I debug it step by step, it works until the very end.
When I try to run it, the dos window comes up in a flash and is gone.
I'm using bloodshed dev-c++ version 4.1, and I'm running Windows XP. When I send the files to my friend, he gets the same problem. However, the Java programs that he compiles work fine. Is it a problem with my compiler?

If you look at sample programs in dev-c++, they all have something like this at the end of the main():

CPP / C++ / C Code:
  system("pause");

This prints a message to "Press any key to continue . . ." and waits for a keypress to end the program. This is to keep the program from exiting and closing its console window until you press a key.

Not all systems have an executable named pause, so this is not very portable. I always recommend getting into the habit of using standard library functions and being operating-system independent as much as possible.

I would recommend something like this for C programs (assuming you have #included stdio.h):

CPP / C++ / C Code:
  printf("Press 'Enter' to continue: ");
  getchar();

For C++ (assuming you have #included <iostream>):

CPP / C++ / C Code:
  std::cout << "Press 'Enter' to continue: " << std::flush;
  std::cin.get();

Regards,

Dave
  #3  
Old 29-Dec-2004, 15:57
NotReallyHere NotReallyHere is offline
New Member
 
Join Date: Dec 2004
Posts: 2
NotReallyHere is on a distinguished road
Thanks alot, that was a big help. :D
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with other programs? leitz C++ Forum 4 14-Nov-2004 05:22
help in c programs kitin21 C Programming Language 4 08-Sep-2004 07:38
strange compile error - code from reputable author!! newbie_cpp C++ Forum 0 06-Nov-2003 16:15
premade forums and other premade php programs invaderz MySQL / PHP Forum 1 06-Jul-2003 02:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:09.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.