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)