Why can I replace one word in a text file but not another? : <p>I'm reading through the following text file word for word a replacing the words "@name@" and "@festival@". My program works perfectly for @name@ but only changes the first @festival@, but not the second. I have no idea why.  </p>

<p>John Doe</p>

<p>Room 213-A</p>

<p>Generic Old Building</p>

<p>School of Information Technology</p>

<p>Programming State University</p>

<p>New York NY 12345-0987</p>

<p>USA</p>

<p>To: @name@</p>

<p>Subject: Season's greetings: @festival@</p>

<p>Dear @name@,</p>

<p>A very @festival@ to you and your family!</p>

<p>Your sincerely,</p>

<p>John</p>

<pre><code>void Main::readFile()
{
while (v.size() != 0) {
    string name;
    name = v.at(v.size()-1);
    v.pop_back();
    std::ofstream out(name + ".txt");
    ifstream file;
    file.open("letter.txt");
    string word;
    string comma;
    char x;
    word.clear();

    while (!file.eof())
    {
        x = file.get();

        while (x != ' ' &amp;&amp; x != std::ifstream::traits_type::eof())
        {
            if (word == "@name@") {
                word = name;
            }
            if (word == "@festival@") {
                word = "THISISATEST!!!!!!!!!!!!!!";
            }
            word = word + x;
            x = file.get();
        }

        out &lt;&lt; word + " ";
        word.clear();
    }
}
</code></pre>
