I'm totally new to C++.  I was messing around with reading and 
writing text from a text file.  I read and displayed the string, "My 
Name is:  ".

Then prompt for a name, append the file, then re-open and re-read 
the file with the appended text.  Everthing works but the re-reading 
of the file.  When I step through the code, it appears that when I 
try to re-read the file, it is already at the end of the file.  
Here's the 
code...

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    ifstream input;
    ofstream output;
    string text;
    string name;

    input.open("c:\\test.txt");
    
    while (!input.eof())
    {
          getline (input, text);
    }
    input.close();
    
    cout << text << endl;

    system("PAUSE");
    
    cout << "Enter Name" << endl;
    cin >> name;
    
    output.open("c:\\test.txt", ios::app);
    output << name;
    output.close();
    
    input.open("c:\\test.txt");
    
    while (!input.eof())
    {
          getline (input, text);
    }
    input.close();
    
    cout << text << endl;
    
    system("PAUSE");
    
    
    return EXIT_SUCCESS;
}

Reply via email to