Is there a reason you're using C-stdio functions to read your file instead of using C++ streams? If you were using C++ streams I doubt that you would be having these issues. By the way you really should avoid using eof() to control a read loop, use the actual read instead.
if (fgets(buffer,100,fp) != NULL)
{
// if last character is newline, replace with null
int len = strlen(buffer);
if (len > 0 && buffer[len-1] == '\n')
buffer[len-1] = '\0';
// add string to end of line
strcat(buffer, a);
cout << buffer << endl ;
}