Handling files in C ++

// **********************************************
// archiv07.cpp
// Show output to printer
// © 1999, Jaime Virgilio Gómez Negrete
// **********************************************

#include <fstream.h>
#include <stdlib.h>

int main ()
{
char text [256];
ofstream printer (“PRN”);
ifstream file (“Tests.txt”);

if (file.fail ())
close << “Error when opening the file: Tests.txt” << endl;
else
{
while (! file.eof ())
{
file.getline (text, sizeof (text));
if (file.good ())
{
printer << text << endl;
if (printer.fail ())
{
close << “Printer write error” << endl;
exit (1);
}
}
else if (! printer.eof ())
{
close << “Error reading the file: Tests.txt” << endl;
exit (1);
}
}
file.close ();
printer.close ();
}

return 0;
}

 

Afflluence Writing Service
Programming in C / C ++: Use of Pointers

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!