Problem with running codes

Discussion in 'C++' started by pkbis28, May 31, 2010.

  1. pkbis28

    pkbis28 New Member

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    i use dev c++ and TC++ for learning c++

    some codes , when i want to run them , they just flush, doesnt show any output, a consol window flashes.
    i can see the output at second's flash, how do i help it?
    here is a sample code that shows the same issue;
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
    cout << "Hi!\n";
    return 0;
    getch();
    }
     
  2. spoddar66

    spoddar66 New Member

    Joined:
    May 25, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    use cin.ignore() after. instead of getch() is what i do. it closes right after the output thats why it flashes. it shows the hi then it closes.

    you can also use getchar() from the cstdlib library which would prolly be the best thing to use.
     
  3. mmondal71

    mmondal71 New Member

    Joined:
    May 25, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    also anything after return 0; in this case will not be run, as return 0; ends the program in this case. You should also use "iostream" instead of iostream.h as iostream.h is old and pre standard c++. include iostream and then have using namespace std; under it , and that will be fine for little educational programs such as this.
     
  4. spoddar66

    spoddar66 New Member

    Joined:
    May 25, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    i didnt even notice the return 0 =/:p
     
  5. pkbis28

    pkbis28 New Member

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    why is that some codes that work fine with TC++ does NOT work well in DevC++ ?:confused:
     
  6. mmondal71

    mmondal71 New Member

    Joined:
    May 25, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    tc++ is HORRIBLY OUTDATED , it has been written before the first c++ standard came out so I'd advise strongly against using it
    Dev-C++ however is based upon GCC one of the most compliant compilers around (there are some compilers that claim to be more compliant but those are commercial Comeau or Intel to name a few) and it's free
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice