C++ Trying to delete used line from txt file : <p>I'm trying to delete used lines from a txt file (questions.txt) and put them into another file (usedQuestions.txt), but right now the code just deletes questions.txt, doesn't put anything in temp.txt or renames it; and doesn't put anything in usedQuestions.txt</p>

<p>This is my code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
using namespace std;

int main () {

    // Loop infinitely
    for (int i = 1; i &gt; 0; i++) {

        // Files
        ifstream txtFile("questions.txt");
        ofstream usedQuestions("usedQuestions.txt");
        ofstream tempFile("temp.txt");

        // Strings, ints etc.
        string question;
        string temp;
        unsigned int lineNum = 1;
        int requestedLineNum;

        // User requests line
        cin &gt;&gt; requestedLineNum;
        cout &lt;&lt; "You have requested question number: " &lt;&lt; requestedLineNum &lt;&lt; endl;

        // Go through lines until the correct line is found
        while (getline(txtFile, question))
        {

            //If the line number is correct, output question
            if (lineNum == requestedLineNum)
            {
                cout &lt;&lt; "Your question is: " &lt;&lt; question &lt;&lt; endl;

                // Write to temporary file, doesn't work?
                while (getline(txtFile, temp)) {
                    tempFile &lt;&lt; temp;
                }

                // Write to file with used questions
                usedQuestions &lt;&lt; question;
            }

            // Set up for while loop to go through lines
            lineNum++;
        }

        // Close and remove questions.txt, rename temp.txt to questions.txt
        txtFile.close();
        remove("questions.txt");
        rename("temp.txt", "questions.txt");
    }
    return 0;
}
</code></pre>
