New Compiler

This is a discussion on New Compiler within the C++ Programming forums, part of the General Programming Boards category; I just got Bloodshed Dev-C++, and I'm having a couple of problems, I write the code and get no errors, ...

  1. #1
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262

    New Compiler

    I just got Bloodshed Dev-C++, and I'm having a couple of problems, I write the code and get no errors, but when I execute the file, nothing happens...

    Here is the code:

    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    int main()
    {
        cout << "I like pants!" << endl;
        getch();
        return 0;
    }
    So any advice, suggestions, comments?
    If you ever need a hug, just ask.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    What do you mean nothing happens? Is it a blank console, or does the program not run?

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    You need to pause before exiting the program. Otherwise the command prompt window closes before you get to see the output.

    If you want to use that getch() to pause the program, you have to include <stdio.h> in addition to <conio.h>.

    But if you include <stdlib.h> or <cstdlib>, you can eliminate both of those io headers and use
    system("pause"); instead of getch();

  4. #4
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    By nothing happening I meant that no window came up at all. If I use system("PAUSE"); then the screen just says Press any key to continue... and after you press a key it closes... this is weird.
    If you ever need a hug, just ask.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    so there is no output?
    that is weird.

  6. #6
    Student Forever! bookworm's Avatar
    Join Date
    Apr 2003
    Posts
    132

    Exclamation The Ultimate Answer!

    Read this carefully and all your problems will be solved !

    In the int main(), before return 0; Enter the following command line-
    std::cin.get();
    This will work for your simple program,but for programs containing std::cin>> you need to type the above twice.
    This will surely make it work.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    Re: The Ultimate Answer!

    Originally posted by bookworm
    Read this carefully and all your problems will be solved !

    In the int main(), before return 0; Enter the following command line-
    std::cin.get();
    This will work for your simple program,but for programs containing std::cin>> you need to type the above twice.
    This will surely make it work.
    getch() is already being used. there is no need to have std::cin.get().

    If you want to use that getch() to pause the program, you have to include <stdio.h> in addition to <conio.h>.
    You shouldn't need stdio to use getch(). I've used it before with just #include'ing conio.h.

  8. #8
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    I've ever got this problem, when I used Dev C++.
    Trying getch() twice can fix it, I have no idea...why.
    Flushing stdout may work false.
    "\n" from stdout seems to appear in stdin.
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    26

    question about system("pause")

    i was wondering where you include system("pause") in your code.thx

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    Re: question about system("pause")

    Originally posted by CobraCC
    i was wondering where you include system("pause") in your code.thx
    wherever you decide you want to pause the program.

  11. #11
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    quote:
    --------------------------------------------------------------------------------
    If you want to use that getch() to pause the program, you have to include <stdio.h> in addition to <conio.h>.
    --------------------------------------------------------------------------------



    You shouldn't need stdio to use getch(). I've used it before with just #include'ing conio.h.
    Which versions of Dev-C++ are you guys using? I'm using ver. 4 with Mingw compiler 2.95.2-1. When I try to compile his code without #include <stdio.h> or <cstdio> I get an error:
    "implicit declaration of function `int getchar(...)'"

    In the file conio.h, the only reference to getch() is just:
    #define getch() getchar()
    and there is no declaration for the function in this file.
    It's declared in stdio.h as
    int getchar ();

  12. #12
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    I'm using mingw 3.2 . I just tried it, works without needing to include stdio.

  13. #13
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Okay instead of using Win32 I used console, and everything works fine, except now I have to relearn things because I don't program in console. Oh well, it can't hurt.
    If you ever need a hug, just ask.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  3. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 05:42 AM
  4. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 10:28 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21