使用c ++通过打印机打印文本文件

使用c ++通过打印机打印文本文件

问题描述:

我想通过喷墨打印机在特定位置打印文本文件.
我已经为此开发了一个代码,但是它会产生一个错误,表明打印机无法打开.

代码如下:

I want to print a text file at a particular location through an inkjet printer.
I have developed a code for this but it produces an error that the printer is unable to open.

The code is given below:

#include <iostream.h>
#include <fstream.h>
#include <conio.h>

void main(void)
{
    clrscr();
    char filename[13];
    char ch;
    cout<<"\nEnter the text file name:";
    cin.getline(filename,13);
    cout<<"\n";
    ifstream fin(filename, ios::in);
    if(!fin)
    {
        cerr<<"\n Cannot open file !\n";
        getch();
        return;
    }
    char const * const PrinterName = "usb001:"; // Identify the printer port.
    ofstream printer(PrinterName); // Open the printer stream.
    if(!printer) // Ensure the printer stream opened ok.
    {
        cerr << "\a\n\tERROR: Unable to open " << PrinterName << endl;
        cout << "\n\tPress the [ENTER] key to return ";
        getch();
        return;
    }

    while (! fin.eof())
    {
        fin.get(ch);
        printer << (ch);
    }

    printer << endl << ends << flush;
    printer.close(); // Finish the print job by closing the printer stream.
    fin.close();

    // Send a carriage return and a formfeed to the printer so that: a) this
    // print job is ejected from the printer, and b) the next print job starts
    // at the top left corner of the page.

    fin.close(); // Close file./
    cout << "\n\n\t\t\t\Printing...";
    cout << "\n\n\ Please press the [ENTER] key to return";
    getch();

    return;
}



请帮助我.



Please help me.

usb001:不是流文件,我认为您不能以这种方式写入打印机.您应该调查 PrintDlgEx [
usb001: is not a stream file and I do not think you can write to printers in this way. You should investigate the PrintDlgEx[^] function for details on how to output to a printer device context.


我想为此使用turbo C ++,而不是VC ++.
I want to use turbo C++ for this, not VC++.


对不起,我不知道turboC.您确定它支持这种打印方法吗?
Sorry I don''t know turbo C; are you sure that it supports this method of printing?