这个程序在完成任何一个动作后自动退出,为什么?

This program is automatically exiting after finishing any one action, why?

我的程序每次发出一个命令后就退出,我找不到合乎逻辑的原因。我已经检查了所有循环和 if 语句的退出代码,但无法找到任何退出代码。 该程序包括许多 类 和函数,但这里是主要的:

int main()
{
    int local_location = 0;
    vector<string>Inventory = { "", "", "" };

    unordered_set<string> excl = { "in", "on", "the", "with" };

    string word;
    array<string, 2> command;
    size_t n = 0;


    command.at(1) = "";
    command.at(0) = "";



    while (n < command.size() && cin >> word) {
        auto search = excl.find(word);
        if (search == excl.end())
            command.at(n++) = word;
    }

    if (command.at(0) == "look") {
        look(command.at(1), local_location, Inventory);
    }
    else if (command.at(0) == "get") {
        look(command.at(1), local_location, Inventory);
    }

    else if (command.at(0) == "drop") {
        look(command.at(1), local_location, Inventory);
    }

    else if (command.at(0) == "bag") {
        bag(Inventory);
    }
    else if (command.at(0) == "go") {
        look(command.at(1), local_location, Inventory);
    }


}

循环标准输入并在处理命令后重置 n 上的条件。

while(cin>>word)
{
   auto search = excl.find(word);
   if (search == excl.end())
       command.at(n++) = word;
   if (n== command.size())
   {
      // process the command
      // reset n=0
   }
}