Okay, So i'm close to finishing up my program. I just need a few more things.
By the way, all of you are AMAZINGLY great. I appreciate all the help.

Alright... My program outputs Names, their Bowling scores, and How many points they have received (the points still need to be worked on, i'll post about that later).

How do I get all of that output to be sent to a printer and be printed?

Dani AI

Generated

As pointed out, there is no portable, standard-C++ printer API. On Windows (Dev-C++ / XP) the practical choices are:

  • Quick and simple: write your output to a text file and ask Windows to print that file (via ShellExecute with the "print" verb, or by launching Notepad with /p, or using the print command). This requires almost no Win32 knowledge and is the fastest way to get a printed copy.
  • Controlled layout: use the Win32 GDI printing model (StartDoc / StartPage / TextOut / EndPage / EndDoc) for properly paginated, fonted output.
  • Raw spooling: use the spooler API (OpenPrinter / StartDocPrinter / WritePrinter) if you must send printer control codes or raw bytes.

A minimal example that creates a text file and asks the shell to print it (works with Dev-C++/MinGW on Windows) — replace the data-writing part with your score output:

#include <windows.h>
#include <shellapi.h>
#include <fstream>

int main()
{
    const char *path = "C:\\temp\\scores.txt";
    std::ofstream ofs(path);
    ofs << "Name\tScore\tPoints\n";
    ofs << "Alice\t200\t10\n";
    ofs.close();

    ShellExecuteA(NULL, "print", path, NULL, NULL, SW_HIDE);
    return 0;
}

Notes and troubleshooting:

  • ShellExecute uses the file association (Notepad for .txt). notepad /p filename or system("print \"file\"") are alternatives but can show UI or behave differently.
  • For formatted pages (fonts, margins), invest time in GDI printing or generate a PDF and print that.
  • If sending raw escape sequences (receipt printers), use the spooler WritePrinter approach.
  • If all you want is a printable table, exporting CSV and printing from Excel (as suggested) is a perfectly valid shortcut.

Recommended Answers

All 6 Replies

Member Avatar for Member #114696

I think there is no way in Standard C++. You will have to use your OS API.
In old non standard compilers there used to be stdprn stream for windows and DOS, but now no longer supported(and ofcourse non stardard hence not advisable too), so I think there is no other way than to use your System API.

How can I do that?

Well, you can start by telling us what your compiler and OS are. :icon_rolleyes:

I'm using Dev-C++ as my compiler, and my OS is Windows XP

I don't imagine you want to do the full blown Win32 solution, so try the options and see if any of them work for you.

Okay, So i'm close to finishing up my program. I just need a few more things.
By the way, all of you are AMAZINGLY great. I appreciate all the help.

Alright... My program outputs Names, their Bowling scores, and How many points they have received (the points still need to be worked on, i'll post about that later).

How do I get all of that output to be sent to a printer and be printed?

Why didn't you just do this in Excel?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.