The most comprehensive detailed explanation of system in C++ on the Internet

This article is the second version with some minor adjustments. Interested friends can read the original article:System in C++_A 32-Wang Blog-CSDN Blog a>

1 Introduction

        The system() function is a very commonly used and useful function in C++ production.

        The effect is similar to the "cmd" console and "bat" file in the system.

        Usually used in C++ character games and C++ trick programs.

        The form is: system("***");.

2. Usage in the program:

        1,system("pause");

                PAUSE can pause file processing and display a message

                As follows↓

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    cout<<"给个点赞+关注吧!";
    return 0;
}

                 Will output:

                After pressing any key:

         2,system("cls");

                ​ ​ ​ ​ cls can clear text content on the page

                As follows↓

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    system("cls");
    cout<<"给个点赞+关注吧!";
    return 0;
}

                 Will output:

                After pressing any key:

                 You can see: the original 

                Disappeared (the screen was cleared)

                This way, we can do something extremely simple:

                Blue Zouyun download ↓

                text(Mitsuka 321)

                csdn resources:

                [Free] Weird Chronicles-Binary New Resources-CSDN Library

 3,system("color ij");

                Color can change the color of text content on the page

                Where "i" is the background color, "j" is the foreground color

                

color comparison table
0 black 8 grey
1 blue 9 light blue
2 green A light green
3 light green B light green
4 red C light red
5 Purple D Lilac
6 yellow AND light yellow
7 White F bright white

                As follows↓

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    system("cls");
    cout<<"给个点赞+关注吧!";
    system("pause");
    system("color 0A");
    return 0;
}

                 In the output:

                After entering it again, the following appears:

 4,system("mkdir x:\y1\y2\y3\...\z");

                mkdir can be in the y3 folder under the y1 folder under the x directory, the y3 folder under the y2 folder... the yn folder folder under

                Create a file named z

                as follows:

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    system("cls");
    cout<<"给个点赞+关注吧!";
    system("pause");
    system("color 0A");
    system("pause");
    system("mkdir D:\helloworld");
    return 0;
}

                In the output:

                After entering again, this appears:

                 Next, you can find that a folder named "helloworld" was created in the D drive

  5,system("del x:\y1\y2\y3\...\yn");

                Del can be in the y3 folder under the y1 folder under the x directory, the y3 folder under the y2 folder... the yn folder folder under

                Delete all items in yn

                as follows:

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    system("cls");
    cout<<"给个点赞+关注吧!";
    system("pause");
    system("color 0A");
    system("pause");
    system("del D:\helloworld");
    return 0;
}

               I created in helloworld on the D drive:

                In the output:

                After entering again, this appears:

                After clicking Enter, enter "Y" after entering "Y"

 

                 Next, you can find that the folder named "helloworld" in the D drive has been emptied

  6,system("start x");

                Start allows the browser to open a URL named x, open a file with path x, etc.

                It’s as follows: (Here we take the URL as an example)

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    system("cls");
    cout<<"给个点赞+关注吧!";
    system("pause");
    system("color 0A");
    system("pause");
    system("start https://i-am-321.mysxl.cn/");
    return 0;
}

               In the output:

                Can Enter, the browser pops up the web page with the URL "https://i-am-321.mysxl.cn" (this is a small page of mine)

                Website) through train:321’s second station | sxl.cn (mysxl.cn) is online

 6,system("shutdown -***");

                Shutdown allows the computer to shut down directly, sleep and many other functions

                

shutdown suffix menu
shutdown -? show help
shutdown -p Shut down directly
shutdown -h hibernate
shutdown -s Shut down after 30 seconds
shutdown -s -t *** (a number represents the delayed shutdown time) Customized time to shut down
shutdown -l Log out
shutdown -a Cancel shutdown plan

                as follows:

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    system("cls");
    cout<<"给个点赞+关注吧!";
    system("pause");
    system("color 0A");
    system("pause");
    system("shutdown -s -t 60");
    return 0;
}

               In the output:

                Then Enter will get an unfortunate news:

                At this time we need:

#include<bits/stdc++.h>
using namespace std;
int main(){
    system("shutdown -a");
    return 0;
}

                In this way, our shutdown task is cancelled!

3. More usage (maybe a bit academic)

        ​ ​ ​ Liver-exploding tips ↓ (The blogger compiled it for more than two hours, please pay attention ヾ(≧▽≦*)o)

system function function comparison table
assoc Display or modify file extension associations.
at Commands and programs scheduled to be run on the computer.
attrib Display or change file properties.
break Set or clear extended CTRL+C checks.
cacls Display or modify a file's access control lists (ACLs).
call Call this one from another batch program.
cd Display the name of the current directory or change it.
chcp  Display or set the number of active code pages.
chdir  Display the name of the current directory or change it.
chkdsk Checks the disk and displays a status report.
chkntfs Display or modify startup time disk checks.
cls Clear the screen.
cmd Open another Windows shell window.
color Set default console foreground and background colors.
comp Compare the contents of two or two sets of documents.
compact Show or change the compression of files on NTFS partitions.
convert Convert FAT volume to NTFS. You cannot convert the current drive.
copy Copy at least one file to another location.
date Display or set the date.
of the Delete at least one file.
you Display files and subdirectories in a directory.
diskcomp Compare the contents of two floppy disks.
diskcopy Copy the contents of one floppy disk to another floppy disk.
doskey Edit the command line, invoke Windows commands, and create macros.
echo Display a message, or turn command echo on or off.
endlocal  Ends localization of environment changes in batch files.
erase Delete at least one file.
exit Exit the CMD.EXE program (command interpreter).
fc Compare two or two sets of files and show differences.
find Search a file for a text string.
findstr Search a file for a string.
for Runs a specified command for each file in a set of files
format Format the disk for use with Windows.
ftype Displays or modifies the file types used for file extension associations.
goto Point the Windows shell to a specified line in the batch program.
graftabl Enables Windows to display the extended character set in image mode.
help Provides help information for Windows commands.
if Perform conditional processing in batch programs.
lablel Create, change, or delete a disk's volume label.
md Create a directory.
mkdir  Create a directory.
mode Configure system devices.
more Displays one results screen at a time.
move Move files from one directory to another.
path Displays or sets the search path for executable files.
pause Pauses batch file processing and displays a message.
popd Restore the previous value of the current directory saved by PUSHD.
print Print text file.
prompt Change the Windows command prompt.
pushd Save the current directory and then make changes to it.
rd Delete the directory.
recover Recover readable information from problematic disks.
rem Log comments in batch files or CONFIG.SYS.
ren Rename the file.
rename  Rename the file.
replace  Rename the file.
is rm  Rename the file.
set Display, set, or delete Windows environment variables.
setlocal Starts localization of environment changes in a batch file.
shift Replace the position of replaceable parameters in the batch file.
sort  Classify the input.
start Launches another window to run the specified program or command.
subst Associate the path with a drive letter.
time Display or set the system time.
title  Set the window title of the CMD.EXE session.
tree Displays the directory structure of a drive or path in graphical mode.
type Display the contents of a text file.
to see Show Windows version.
verify Tells Windows whether to verify that the file was written to disk correctly.
vol Display the disk volume label and serial number.
xcopy Copies files and directory trees.

        At present, the blogger has collected only the above 71 system function commands. If there are errors or incomplete comments, please share them in the comment area ( •̀ ω •́ )!

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"HELLO WORLD\n";
    system("pause");
    system("cls");
    cout<<"给个点赞+关注吧!";
    system("pause");
    system("color 0A");
    system("pause");
    system("cls");
    cout<<"给个关注再走d=====( ̄▽ ̄*)b吧!";
    return 0;
}

 The program + source code mentioned this time (Lan Zuoyun) download↓

text, secret: 321

There should be no one (lll¬ω¬)

Guess you like

Origin blog.csdn.net/HenryC0509/article/details/132782597