Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Dev-C++ Compiler

  1. #1
    Right turn Clyde Nokia's Avatar
    Join Date
    Aug 2003
    Location
    Button Moon
    Posts
    1,696

    Dev-C++ Compiler

    Hi,

    I am just starting to learn about C++ and have bought a book (SAMS Teach yourself C++) it had a cd that came with it which has the Dev-C++ IDE compiler on it.

    As the book teaches you how to use this compiler in conjunction with the programs it teaches you I am trying to learn how to use it.

    I have a problem though, after I have compiled, linked and debugged the programs in the book whenever i try to run them the command prompt screen flashes up for a split second then disappears instead of staying up so I can see the results of what it have done.

    I am running WinXP Home and have updated Dev-C to the latest version.

    Could anyone give me any ideas as to what I am doing wrong or how I can rectify the problem, I have changed all of the compilers settings to what it says in the book but to no avail!

    As i said I am quite new to programing and havent got a clue about whats going wrong!

    Thanks in advance for any help!

  2. #2
    Senior Member
    Join Date
    Oct 2003
    Posts
    234
    Try running your programs from the command line rather than through the IDE. I've never used Dev-C++, but this usually happens when you try to run a DOS program as a Windows program. Alternatively, add code like this at the end of your main() function

    Code:
    char buffer;
    printf("Press Any Key To Continue: ");
    getc(buffer);
    return 0;
    Hope this helps.

  3. #3
    Senior Member Zonewalker's Avatar
    Join Date
    Jul 2002
    Posts
    949
    open up the command line interface first - then type in the path and .exe. the command prompt will stay open.

    If you d/l the XP power tools there's a modification that when you open the right click menu in windows explorer will allow you to 'open command window here' - this will open the command line at which ever folder you're in using windows explorer. handy if you navigate to the window you've stored your c++ exe in

    Z
    Quis Custodiet Ipsos Custodes

  4. #4
    Banned
    Join Date
    Aug 2003
    Posts
    130
    I had this same problem. I use dev-c++ 5 (beta).

    Code:
    int main()
    {
         system("PAUSE");            //add this before return 0;
         return 0;
    }
    In dev-c++ when you create a new cpp file i think it still adds this in there.

    That should solve your problem. You could still open it in comand but i think the above way is better.

  5. #5
    AntiOnline n00b
    Join Date
    Feb 2004
    Posts
    666
    I have a problem though, after I have compiled, linked and debugged the programs in the book whenever i try to run them the command prompt screen flashes up for a split second then disappears instead of staying up so I can see the results of what it have done
    hi
    it's a matter of split seconds ,you have to be pretty sharp learning C++

    It happens with all the compilers i used be it TurboC++ , Microsoft Quick C or VC++.....

    This generally happens with programs that do not need user intervensions like the program below dosen't need the user to do anything , the programs runs does the adding and displays output. If it would have been dos it would have transferred the control back to the prompt and you would have been able to see the output just above the current prompt.

    But under Windows the Command Prompt shows up does the calculations shows the result and disapeers . I think VC++ counters this problem by adding a small code into the programs and at the end of every programand the command Prompt windows says "Press any key to Continue" . It does this by using the Getch() ; it waits for the user to press any key. ............I have made it a habit of writing getch() at the end of every C,C++ ,program i write.

    Try using getch(); at the end of the code

    e.g.
    Code:
    #include<iostream.h>
    
    void main()
    {
    int i,j;
    i=2;
    j=8;
    int add=i+j;
    cout<<add<<endl;
    
    }
    this one Blinks for less than a second and poof.. Dissapeers
    just add getch(); at the end

    Code:
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    int i,j;
    i=2;
    j=8;
    int add=i+j;
    cout<<add<<endl;
    getch();
    }
    this one waits for me to press any key after the program has finished.

  6. #6
    Right turn Clyde Nokia's Avatar
    Join Date
    Aug 2003
    Location
    Button Moon
    Posts
    1,696
    Thanks all for the help! it certainly helped me understand what was happening a bit more. I think the quickest way i found was to add the " system("PAUSE"); " before the return 0;
    so thanks for that mikem0327.

    I tried the getch(); way SwordFish_13 but it kept coming up as an error when i compiled it, i even cut and pasted the code you wrote here and it still came up as an error, could this be my compiler??

    Thanks again all

  7. #7
    AntiOnline n00b
    Join Date
    Feb 2004
    Posts
    666
    What's the error message is it "Function getch(); should have a Prototype" . Did you include the #include<conio.h> conio header file because getch() is defind in the conio header file


    EDIT]
    Originally posted here by gothic_type .

    hope you get the gist of what I'm trying to say
    I think this will give you a gist of what gothic_type is trying to say

    i've seen several people use system("PAUSE") when they want to delay their programs. i'm not sure who's teaching this method, but it's a bad habit.
    by calling system(), you are invoking the default shell. the shell then executes the command line given to it ("PAUSE", in this case). that is, it runs the 'pause.exe' program. so, now your simple C/C++ program is relying on two external programs for a stupid thing like pressing a single key. what if someone deleted or renamed 'pause.exe'? what if someone tried to compile your program on unix, or a mac?(okay getch() too is not portable but it dosent invoke other programs) it wouldn't work. you'd get an annoying shell message and no pause. besides, why have the overhead of launching 2 programs, I mean its like bringing a Cannon out to kill a fly the fly might get killed but the cannon might harm you too.

    --Good Luck--

    [EDIT 2]

    I just Downloded DEV C++ it's VER 4.9.8.0 on my slooooooooow Dial-up at about 4 Kbits /per second yep it's that slow *yawn*

    To tell you the truth i can't even compile the "Hello World" program in it After working for almost one year in C++ . damm Turbo C++ has spoiled me .....

    after half an hour of labourious struggel we are finally getting somewehere, ureka i have compiled the "Hello world" program.

    try this one i have just compiled it in DEV C++

    Code:
    #include <iostream>
    #include<conio.h>
    using namespace std;
    
    int main ()
    {
      cout << "Hello World!" << endl;
      
      getch();
      return 0;
    }
    Or you can also use this, it dosen't use getch()
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
      cout << "Hello World!" << endl;
      cout << "Press ENTER to continue..." << endl;  
      cin.get();                                                          
      return 0;
    }
    these two line in bold at the end of the program will also work.

    And now i am going to uninstall DEV C++ . i just love Turbo C++ Ver 3 even more now Plain and simple.

    [Edit3
    If Portability is a issue with your programs then i guess Getch(); is a bad idea, you wouldn't find it in Linux or MAC . There are hell lot of ways to do it you just have to make it wait for a key press. if you are not going to port your programs to another system (*nix etc) then i guess conio.h would be quite helpful to you it contains many imp functions (getch(), getche(),clrscr(),putch() etc most of which are uncompitable winth *nix etc.

  8. #8
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    Nokia, you should use getch() like SwordFish_13 advised rather than system("PAUSE") because when you call system(...) you are getting the computer to run a command using it's cli (command language interpreter e.g. dos, the bash shell...) It's not a good idea to do that if at all possible in case you need to port your programs, and also, calls to system(...) don't usually run very fast.

    I don't believe getch() is portable, so maybe that isn't a concern, but the speed issue is. If you decide to clear your screen using system("cls"), it can slow your program right down.

    Sorry that post is a bit garbled...hope you get the gist of what I'm trying to say.

    ac

  9. #9
    Senior Member
    Join Date
    Jul 2002
    Posts
    339
    Everybody, getch() is not portable. I think it's as bad as system("PAUSE"). Use getchar() instead, it's simple, portable and doesn't need any external shell.

    Also, follow this thread for a discussion of Standard C:
    http://www.antionline.com/showthread...hreadid=254573

    Peace always,
    <jdenny>
    Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
    I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds


  10. #10
    Right turn Clyde Nokia's Avatar
    Join Date
    Aug 2003
    Location
    Button Moon
    Posts
    1,696
    No i didnt include the #include<conio.h> header SwordFish_13, obviously that was where I was going wrong!

    I have just tried a few programs out the book and added it along with getch(); and it works everytime, so thank you very much for that it has certainly solved a big problem for me.

    Just out of intrest is it possible or would you recommend against adding it to most C programs or are the occasions when you shouldnt add it? In other word would I be OK to add it to all the programs I am learning?

    Thanks for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •