刚开始写c++代码,编译时遇到一个问题:
我想写一个模仿cmd.exe(命令提示符程序),以下是源码:
#include <iostream>
#include <cstdlib>
//#include <unistd.h>
#include <string>
using namespace std;
int main() {
char dos_command;
while (true) {
cout << "D:/Program Files/Cpp>";
cin.get(dos_command);
system(dos_command);
}
return 0;
}
网上查了好久也没查到答案,请问如何解决?
复习一下基础知识吧。
#include <iostream>
#include <cstdlib>
//#include <unistd.h>
#include <string>
using namespace std;
int main() {
char dos_command[10];
while (true) {
cout << "D:/Program Files/Cpp>";
cin >> dos_command;
//cout << dos_command;
system(dos_command);
}
return 0;
}
char dos_command;
->
char dos_command[100];
或者
string dos_command;