C++做的一个玩具shell

效果展示:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
提供的命令有:
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;
 } 

猜你喜欢

转载自blog.csdn.net/weixin_44895666/article/details/108685175