Код: Выделить всё
wc -w "Hello World!" Код: Выделить всё
echoКод: Выделить всё
Hello World!Код: Выделить всё
string Reader::readLine() {
cin.clear();
char line[maxLineLength];
cin.getline(line, maxLineLength);
return line;
}
Command* Parser::parseLine(const string& line) {
stringstream ss(line);
string word;
string words[3] = {"", "", ""};
size_t pos = line.find('"');
int hasQuote = 0;
if (pos != string::npos) {
hasQuote = 1;
}
for (int i = 0; i < 3; i++) {
if (ss >> word) {
words[i] = word;
}
else {
words[i] = "";
}
}
string function = words[0];
string opt, arg;
if (words[1].front() == '-' && !hasQuote) {
opt = words[1];
arg = words[2];
}
else if (words[1].front() == '"') {
opt = "";
arg = line.substr(pos, line.length());
}
else if (words[1].front() == '-' && hasQuote) {
opt = words[1];
arg = line.substr(pos, line.length());
}
else {
opt = "";
arg = words[1];
}
Command *res = nullptr;
if (function == "echo") {
if (arg.empty()) {
arg.clear();
string tmp;
while (getline(cin, tmp)){
arg += tmp + "\n";
}
cin.clear();
arg = "\"" + arg;
arg[arg.length() - 1] = '\"';
}
res = new EchoCommand(arg);
}
else if (function == "date") {
res = new DateCommand();
}
else if (function == "time") {
res = new TimeCommand();
}
else if (function == "touch") {
res = new TouchCommand(arg);
}
else if (function == "wc") {
res = new WcCommand(arg, opt);
}
else {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79239778/program-crashes-after-eof-is-sent[/url]
Мобильная версия