C # Clear the screen in the console

Source: Internet
Author: User

I recently wrote a console program. This program has a simple function, that is, exporting data from the database (specifying the table name, specifying the table field name) to the WORD file, and the program has been completed, during the test, it was found that after you export a database table, if you want to export data from another table, you have to re-run the program. This is obviously not good. However, if you use a loop or a goto statement in a program, there are too many texts in the console. So I finally thought about whether to allow the console to automatically clear the screen and export the next database table after importing a database table. Then I searched the internet for a long time and did not find a satisfactory answer. The "clear screen" method on the Internet is to output n carriage returns. I think this is not a clear screen at all. I suddenly thought of using C ++ to write a clear screen DLL, and the result was satisfactory. The following is a step-by-step implementation of the C # language in the console:

(1) Open VS2005 and create a C ++ class library project named CLS;

(2) Open the CLS. h file and rename the class name to "CLS ";

(3) Open the CLS. cpp file and introduce the "windows. h" file;

// This is the main DLL file.

# Include "stdafx. h"
      # Include "windows. h"
# Include "CLS. h"

(4) add static methods in the CLS class (the access attribute is public)

Public ref class CLS
{
Public:
Static void cls ()
{
System ("cls ");
}
};

(5) Compile the entire project and introduce CLS. dll in the CLS/debug/folder into the C # project;

(6) Call CLS. cls () to clear the screen. You can also implement pause and other functions. The method is the same as above.

So why? As long as you have learned. net FrameWork should be very clear, because no matter whether it is C ++, C, VB or C # Language, it will eventually generate the IL (Intermediate Language) Language, therefore, no matter which language you use to write programs, you can use each other.

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.