Detailed programming of the C + + control Console (console)

Source: Internet
Author: User

Objective:

The control of the console text window is based on the Win32 API (Win32 API can be understood as a collection of functions provided by Microsoft to us);

Example 1:

#include <stdio.h>int  main () {    printf ("Hello world!\n")  ;     return 0 ;}

Operation Result:

In Example 1, we use the printf () function to output the Hello world! in the console but when we want to erase the contents of the previous output, the function in stdio.h does not meet our needs, and we need to use the Win32 API function

Example 2:

#include <stdio.h><windows.h>int  main () {    printf ("Hello world!\n");    Sleep (+);    System ("cls");     return 0 ;}

Operation Result:

Example 2, the use of sleep () in the Windows.h, the system () function, the Sleep (1000) function function for a delay of 1s after the program runs down, the system ("CLS") clears the content, so in Example 2, the program runs display Hello world! It clears in a second.

The API functions for the console window operations are as follows:

Getconsolescreenbufferinfo Getting the console window information

Getconsoletitle getting the console window title

Scrollconsolescreenbuffer moving a block of data in a buffer

Setconsolescreenbuffersize changing the specified buffer size

Setconsoletitle Setting the console window title

Setconsolewindowinfo Setting Console window information

Example 3:

#include <windows.h><stdio.h>int main (void) {       Setconsoletitle (L  "Hello world! " // Set Window caption       printf ("Hello world! " );        return 0 ;}

Operation Result:

In Example 3, we used the setconsoletitle () function; The window title has changed to a hello world!.

The use of other functions, can be degrees, here for the moment do not repeat .....

Detailed programming of the C + + control Console (console)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.