programs are not showing!

This is a discussion on programs are not showing! within the C++ Programming forums, part of the General Programming Boards category; I just started C++ today and im using Dev-C++ as a compiler. Ive tried many examples, including the ones in ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    4

    Question programs are not showing!

    I just started C++ today and im using Dev-C++ as a compiler.
    Ive tried many examples, including the ones in this web's tutorial, but when i compile and run them the programs do not show on the screen,
    i am using cin.get(); so i think the problem is that i need to use some function like "Show on Screen"
    well, here is the example i am using:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
      cin.get();
    }
    Please change the code as needed to make the window show
    Thank you in advance

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    
    int main()
    {
      cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
      getch();
    }

    or...
    Code:
    #include <iostream>
    
    
    using namespace std;
    
    int main()
    {
      cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
      system("pause");
    }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,767
    Or even, READ THE FAQ

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    I don't know what the problem is. Your use of cin.get() is correct, so using getch() or system("pause") or reading the FAQ will not work or will just mask the problem.

    How are you setting up and running the project in Dev-C++? Include details like what menu item you choose and what buttons you push.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    10
    Sometimes I have to use cin.get(); to times in a row. Then it works for me.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    4
    Thank you for the replies guys, but i read the FAQ and tryed both of the examples above using getch(); and system("pause"); in both cases the compiler shows the following error:

    implicit declaration of function `int system(...)'

    or this one when using getch();

    implicit declaration of function `int getchar(...)'

    Thanks in advance, and i hope for someone to be able to solve this.

    Btw, im using Execute->Compile and then Execute, ive also tryed using run uder the same menu and "Compile and Run". Also i belive that the compiler is working correctly becausewhen i create a new document the code that comes in it actually works and the window is shown on the screen, here is the code:

    Code:
    #include <windows.h>
    
    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
    int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof(WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL; /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use light-gray as the background of the window */
        wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    
        /* Register the window class, if fail quit the program */
        if(!RegisterClassEx(&wincl)) return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx(
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",         /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow(hwnd, nFunsterStil);
        /* Run the message loop. It will run until GetMessage( ) returns 0 */
        while(GetMessage(&messages, NULL, 0, 0))
        {
               /* Translate virtual-key messages into character messages */
               TranslateMessage(&messages);
               /* Send message to WindowProcedure */
               DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
        return messages.wParam;
    }
    
    /* This function is called by the Windows function DispatchMessage( ) */
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
               case WM_DESTROY:
               PostQuitMessage(0);        /* send a WM_QUIT to the message queue */
               break;
               default:                   /* for messages that we don't deal with */
               return DefWindowProc(hwnd, message, wParam, lParam);
        }
        return 0;
    }
    When using this code, it actually shows the window and i belive it may be related to the part of the code i marked in red

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    There is a difference between a console application and a windows application. In a console application like the one you showed in the first post, a text-based console window appears with the output of your program. In a Windows program like the one in this last post, a regular window appears.

    If you want to do console programming like the original example, make sure you create a console project in Dev-C++ and look for the console to open up. If you want to have a regular Windows window, then you must use Windows programming like your latest example.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    implicit declaration of function `int system(...)'
    You need to include <cstdlib> for system().

    or this one when using getch();

    implicit declaration of function `int getchar(...)
    Evidently you're using getchar(). For getchar(), you need <cstdio>, and for the non-standard getch[e](), you usually need <conio.h>.

    Sometimes I have to use cin.get(); to times in a row. Then it works for me.
    Read the FAQ, as Salem suggested.
    [edit]
    FAQ > How do I... (Level 1) > Stop my Windows Console from disappearing everytime I run my program?
    FAQ > How do I... (Level 1) > How do I get my program to wait for a keypress?
    [/edit]
    Last edited by dwks; 12-29-2005 at 03:57 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    All of that stuff is irrelevent to the OPs problem. The original use of cin.get() was correct.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Yes, but it might help the "Sometimes I have to use cin.get(); to times in a row. Then it works for me." person.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    That person was merely attempting to help the OP, not ask a question. Since the original problem has not been resolved, trying to help others that didn't even ask for help just clutters the thread and makes it more difficult for the original poster to get the help he or she is looking for.

  12. #12
    Registered User
    Join Date
    Dec 2005
    Posts
    4
    Thanks a lot Daved, i still have one more question, when creating a console application the window appers as an "old-style" MS2 window, is there any way to change that to a normal Windows XP window without making it a windows application?

    Thank you gain

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    No, if you want a [non-console] window, you need a Windows application.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Registered User
    Join Date
    Aug 2005
    Posts
    10
    Quote Originally Posted by dwks
    Yes, but it might help the "Sometimes I have to use cin.get(); to times in a row. Then it works for me." person.
    It works for me 2 times in a row.

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Well, that's only if you have "\n" in the input buffer. If you have "some more junk\n" in the buffer, it won't work. Read the FAQ! (See, Daved? )

    [edit]
    This one might be relevant, too: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    Especially the ignore() line.
    [/edit]
    Last edited by dwks; 12-29-2005 at 04:17 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 07:32 AM
  2. How come Dev C++ cant run some programs??
    By Sephiroth in forum C Programming
    Replies: 41
    Last Post: 09-17-2005, 06:35 AM
  3. Way to get the current open programs displayed?
    By CPPguy1111 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2005, 01:24 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 04:12 AM

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