Imitates print command - C++ File Stream

C++ examples for File Stream:stream

Description

Imitates print command

Demo Code

#include <fstream>
#include <iostream>
using namespace std;
#include <process.h>
int main(int argc, char* argv[])
{
  if (argc != 2)/*from w  w  w . j  a  va  2s.c om*/
  {
    cerr << "\nFormat: oprint filename\n";
    exit(-1);
  }
  char ch;                       //character to read
  ifstream infile;               //create file for input
  infile.open(argv[1]);        //open file
  if (!infile)                  //check for errors
  {
    cerr << "\nCan't open " << argv[1] << endl;
    exit(-1);
  }
  ofstream outfile;
  outfile.open("PRN");           //open it for printer
  while (infile.get(ch))   //read a character
    outfile.put(ch);            //write character to printer
  outfile.put('\x0C');           //formfeed to eject page
  return 0;
}

Related Tutorials