C ++循环仅读取第一行

时间:2018-10-01 02:22:53

标签: c++ loops

我需要这段代码来读取循环的每一行,但是它只读取第一行。它是从一个共有9个加扰字的文件中提取的,应该通读所有9个加扰字并解扰它们,使之成为4个字母字。有什么建议吗?

    position = 0;


    test_word = puzzle;
    cout << "Is " << test_word << " a word? " << endl;
    while (!wordpuzzle.eof())
    {
        for (int i = 0; i < puzzle.length(); i++);
        {
            while (position <= puzzle.length() - 4)
            {
                test_word = puzzle.substr(position, 4);
                cout << "Is " << test_word << " a word? " << endl;

                while (!dictionary.eof())  // Loop through dictionary comparing each word.
                {
                    dictionary >> word;   // Get a word from the dictionary
                    counter++;
                    if (word == test_word)
                    {
                        cout << "The word " << test_word << " was found in the scramble. "
                            << " Word " << counter << endl;
                        found = true;
                        break; // Exit while loop if word is found
                    }
                }
                while (!dictionary.eof())  // Loop through dictionary comparing each word.
                {
                    dictionary >> reverseword;   // Get a word from the dictionary
                    counter--;
                    if (reverseword == test_word)
                    {
                        cout << "The word " << test_word << " was found in the scramble. "
                            << " Word " << counter << endl;
                        found = true;
                        break; // Exit while loop if word is found
                    }
                }
                if (!found)
                    cout << "The string " << test_word << " is not a word." << endl;
                dictionary >> word;
                // Reset everything for the next substring from the scramble.

                dictionary.clear();
                dictionary.seekg(0, ios::beg);
                position++;
                counter = 0;
                found = false;
            }
        }
    }
    cout << endl << endl;

    dictionary.close();
    system("pause");
    return 0;
}

0 个答案:

没有答案