press any key to continue

This is a discussion on press any key to continue within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by csonx_p Working with console applications, sometimes you need to echo something What do you mean? -- Mats...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by csonx_p View Post
    Working with console applications, sometimes you need to echo something
    What do you mean?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    What do you mean?

    --
    Mats
    Well for some strange reasons the text on the screen would pass without you seeing it, especially if you clearing screens for new text. I need pause for that

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by csonx_p View Post
    Well for some strange reasons the text on the screen would pass without you seeing it, especially if you clearing screens for new text. I need pause for that
    NOT clearing the screen would solve that particular problem.

    But if you are doing screen clearing, then you are using non-portable code [or calling system() - which I think is worse], so you may as well throw in a a "getch" into the mix of non-portable functions. Just make sure that you put it in a special place, so that when you try to do the same thing on a different OS, you can easily replace what the actual function is.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    NOT clearing the screen would solve that particular problem.

    But if you are doing screen clearing, then you are using non-portable code [or calling system() - which I think is worse], so you may as well throw in a a "getch" into the mix of non-portable functions. Just make sure that you put it in a special place, so that when you try to do the same thing on a different OS, you can easily replace what the actual function is.

    --
    Mats
    Mhh, its good that i raised this issue then because a friend told me its not good to clear screens, but he didn't explain why. Exactly how do i transfer outputs on new screens? Obviously i can put the entire program on the same screen ... I would like to write portable code, so help me please!!!!

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    If you want to write portable code, you should probably give up on console apps.
    Typically, whatever you do, you cannot clear the screen is a truly portable way. Here's more info anyway:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    If you want to write portable code, you should probably give up on console apps.
    Typically, whatever you do, you cannot clear the screen is a truly portable way. Here's more info anyway:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    My guess is you are suggestion that i use
    Code:
    #include <windows.h>
    
    void clear_screen ( void )
    {
      DWORD n;                         /* Number of characters written */
      DWORD size;                      /* number of visible characters */
      COORD coord = {0};               /* Top left screen position */
      CONSOLE_SCREEN_BUFFER_INFO csbi;
    
      /* Get a handle to the console */
      HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
    
      GetConsoleScreenBufferInfo ( h, &csbi );
    
      /* Find the number of characters to overwrite */
      size = csbi.dwSize.X * csbi.dwSize.Y;
    
      /* Overwrite the screen buffer with whitespace */
      FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
      GetConsoleScreenBufferInfo ( h, &csbi );
      FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
    
      /* Reset the cursor to the top left position */
      SetConsoleCursorPosition ( h, coord );
    }
    over system("cls");, which am happy to do if it means portability .....

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Quote Originally Posted by csonx_p
    over system("cls");, which am happy to do if it means portability .....
    The part that means portability is the abstraction of clearing the screen to a function, in this case one named clear_screen. You could also have written:
    Code:
    void clear_screen()
    {
        system("cls");
    }
    To actually be portable, you would need to implement clear_screen() differently as required by each supported platform, and then build the program such that the correct version of clear_screen() is chosen for the given platform.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    There's no way to do it portable since C/C++ lacks facilities to clear the screen.
    Everything you do will be unportable, relying on some platform-specific API.
    But that mentioned, the best thing to do is take laserlight's advice. This is typically how big libraries make themselves portable, including Boost I would think.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Downloaded pdcurses, just by including <curses.h>, i get strange compile warnings & errors...

    some here ..

    Code:
    warning C4005: 'MOUSE_MOVED' : macro redefinition  
    error C2059: syntax error : '('
    error C2039: 'usr_iter' : is not a member of 'std::vector<_Ty>'
    error C2668: 'std::vector<_Ty>::end' : ambiguous call to overloaded function
    etc...

  10. #25
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    anyone????????????

    Or is it because i have windows.h included somewhere?

  11. #26
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Might be #define clashes, or some such. It is difficult to say.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The "macro redefined" usually tells you where it was previously defined [although sometimes you have to look at the raw compiler output rather than the error summary to see that].

    Including windows.h should be limited to places where you REALLY have to do that - if nothing else because it is really large and it takes quite some time to compile lots of files that include windows.h.

    You probably do not want to include curses.h and windows.h in the same source file - there should be no need to use windows.h in a curses application - if you are calling some windows function that curses doesn't have it's own version of, then you probably want to isolate that, as described previously, in a "windows stuff" source file, and then include a header file like "osindeps.h" that define the OS dependant functions in a OS-independent way [for example, if you need a delay/sleep function, Windows and Linux do different variants here, so you'd put your own os independent function declaration in osindeps.h, and then make the translation in your widnows_stuff.c or linux_stuff.c].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

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

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM

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