10

コードブロックで出力コンソールをクリアする方法?? なぜ clrscr(); しないのですか? Code::Blocks で動作しますが、Borland で動作しますか??

私はすでに試しました:

cout << "\x1b[2J\x1b[1;1H" << flush;
cls() ;
4

11 に答える 11

1

インターネットで検索しただけです。

ソースを思い出せませんが、これが今のところ最も正確なはずです。

#include<windows.h>    

void clear_screen ()
{
    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 );
}

今、あなたがしなければならないのは、電話するだけです clear_screen()

編集:

ソースを見つけました: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1031963460&id=1043284385

于 2015-06-01T05:37:21.560 に答える
0

「MinGW\include」フォルダーの conio.h を開き、これらの行を一番下に追加して conio.h を保存します。

#include <stdlib.h>
void clrscr()
{
   system("cls");
}

clrscr(); これですべてです。動作します

于 2016-06-25T16:30:04.007 に答える
0
#include <stdlib.h>

int main()
{
  system("cls");
}

または、system("cls"); を追加するだけです。あなたの主な機能で。注: stdlib.h ヘッダー ファイルが必要なので、含めることを忘れないでください。

于 2015-09-15T20:44:17.710 に答える