从命令行启动时,在 for 循环期间不显示 C++ cout 语句

C++ cout statements not displayed during a for loop when launched from command line

我正在为我的计算机科学课程中的一个项目编写代码,我正在测试我的算法以查看它是否有效以及速度有多快。我知道该算法有效,因为当我在 Visual Studio 2013 年启动该程序时,我得到了正确的输出。但是,当我从命令行中的 Visual Studio 项目文件夹或从 windows 资源管理器启动 .exe 时,前两个 cout 语句正确显示,但 for 循环期间的 cout 语句未显示根本。同样,这仅在我在 Visual Studio 之外启动 .exe 时发生。这不是一个大问题,但我想知道这里发生了什么。谢谢

这里是 int main()(前 2 个 cout 工作,其他的不工作):

int main() {
    // declare input stream for reading dctnryWords.txt
    ifstream inFile;
    // create a pointer to memory in the heap
    // where each word in the dictionary will be stored
    string* words = new string[DICTIONARY_SIZE];
    // create a vector of forward_lists to hold
    // adjacent words for each word in the dictionary
    vector< list<string> > adjacents(DICTIONARY_SIZE);
    // open dctnryWords.txt
    inFile.open("dctnryWords.txt");
    // load words into RAM
    cout << "Loading words into RAM took: "
        << time_call([&] { copyDictionary(inFile, words); })
        << "ms\n";

    cout << "Finding adjacent words took: "
        << time_call([&] { searchAdjacents(words, adjacents); })
        << "ms\n";

    for (int i = 0; i < DICTIONARY_SIZE; i++) {
        if (adjacents[i].size() >= 25) {
            cout << words[i] << "(" << adjacents[i].size()
                << "): ";
            for (list<string>::const_iterator j = adjacents[i].cbegin(); j != adjacents[i].cend(); j++) {
                cout << *j << " ";
            }
            cout << endl << endl;
        }
    }

    return 0;
}

我敢打赌你的程序在其他地方启动时找不到 "dctnryWords.txt"...因为它会在当前目录中查找,当你 运行 它在 VS 之外。