I have already declared it as fstream...
Here is the whole program -
Code:
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char buffer[256];
fstream myfile;
myfile.open("test.txt", ios::out);
myfile << "This is my first entry.\n";
myfile.close();
myfile.open("test.txt",ios::in);
myfile.getline(buffer,100);
cout << "The file originally contained: " << buffer << "\n";
myfile.close();
myfile.open("test.txt", ios::app);// <--- There it is!!!
myfile << "This is my second entry.\n";
myfile.close();
myfile.open("test.txt",ios::in);
myfile.getline(buffer,100);
cout << "The file now contains: " << buffer << "\n";
myfile.close();
myfile.open("test.txt", ios::out);
myfile << "This is my third entry.\n";
myfile.close();
myfile.open("test.txt",ios::in);
myfile.getline(buffer,100);
cout << "The file now contains: " << buffer << "\n";
myfile.close();
return 0;
}
Why, exactly, will ios::in ios::out work, but ios::app wil not?