Hi,
Does keeping your "cout" statements within the while loop helps?
--- In [email protected], "allan_blackford" <[EMAIL PROTECTED]>
wrote:
>
> 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);
cout << text << endl; // Add this here
> }
> 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);
cout << text << endl; // And here!!
// I hope this helps!
// ~Saurabh
> }
> input.close();
>
> cout << text << endl;
>
> system("PAUSE");
>
>
> return EXIT_SUCCESS;
> }
>