Code:
#include <fstream.h>
#include <iostream.h>
#include <string.h>
These are the older headers, use the new ones:
Code:
#include <fstream>
#include <iostream>
#include <cstring> // Or <string>? Either way, you don't look like you really need this one
Code:
using namespace std;
int main()
{
ifstream fin("file1.txt");
char message[512];
cout << "Enter a message:" << endl;
cin >> message ;
fin.open("file1.txt",ios::app);
Your code is trying to open a file twice, the first line after the '{' opens a file called file1.txt for input. The fin.open() command then tries again to open the same file in append mode. Of course you should only need to open the file for input once. Also, append mode is only for output files, not input files.
Code:
fin.getline(message, 512);
This is going to overwrite whatever the user typed into the buffer in response to the above prompt to enter a message. Are you simply thowing that input away in favor of getting a line from the input file or do you need to do something with that input before you get the line from the file?
Code:
ofstream SaveFile("file1.txt",ios::app);
SaveFile << message;
SaveFile << ".\n" ;
SaveFile.close();
return 0;
}
You should probably close the input file fin before you open another file object referencing the same file. The declaration of the SaveFile object needs to do a bitwise OR with ios::out, i.e. ofstream SaveFile("file1.txt",ios::out|ios::app);
What sentence are you trying to write (append?) to the file? The one you appear to be reading from the input file, or the one you get from the user at the prompt?