效果展示:
提供的命令有:
hello
color
cls
quit
exit
源代码:
#include <iostream>
#include <cstdlib>
#include <cstring>
int main()
{
using namespace std;
system("cls");
cout << "my Shell >>> ";
// string myinput;
char myinput[10];
scanf("%s",myinput);
// cin >> myinput;
while ( myinput != '\0' ){
if (!strcmp(myinput, "exit")){
exit(0);
}
if (!strcmp(myinput, "quit")){
exit(0);
}
if (!strcmp(myinput, "cls")){
system("cls");
}
if (!strcmp(myinput, "hello")){
cout << "Hello, user Bob, nice to meet you" << endl;
}
if (!strcmp(myinput, "color")){
system("color 2f");
}
cout << "my Shell >>> ";
scanf("%s",myinput);
}
return 0;
}