answersLogoWhite

0

Printout of output in c plus plus?

Updated: 8/10/2023
User Avatar

Wiki User

9y ago

Best Answer

This question could mean one of two things: either the program should print its machine code, or it should print its source code. Printing the machine code is easy enough since the first argument passed to the program contains the executable name. So you simply need to open this file as a binary input file and redirect the content to std::cout. Some characters will be non-printable of course, so it might be better to convert every byte to its hexadecimal equivalent and print that instead.

A machine code program that prints its own source is somewhat more complex. Firstly, you need to know which file or files to print. If the source code is contained in a single source file then it's relatively simple to print the one file provided you tell the program which file to print. Using the executable file name to derive the source code file name is one possibility. And if the source has a header this could also be derived.

If the program source is spread over multiple sources with many includes then you should locate the project file that lists all the files used by the project and parse this file in order to obtain each file name you need to print. You can safely ignore standard library includes and binary library links since you'd only be interested in your own user-defined files. Ideally these will all be placed in the same folder so they'll be easy to identify. You might also have re-usable code modules in other folders but if they're all within the same folder hierarchy they should be easy to identify as well. Once you have a list of all the project files files you can go ahead and print them.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

To print the output of a C++ console program (or indeed any console program), redirect the output to a file then print the file. If you have a line printer attached to LPT1, redirect to LPT1. Redirection is achieved from the command line. Redirection does not affect error output (std::cerr), only standard output (std::cout).

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

You print the output of a C++ console program by redirecting the output to the appropriate output stream (display, printer or file). This is achieved via the command line. For example:

progname >> LPT1

In this case, all output that is directed to stdout (which defaults to the display device) will be redirected to the device associated with LPT1 instead. Output that is directed to stderr will not be affected, so errors will be directed to the default stderr device (usually the display device).

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Yes.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Printout of output in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the Example Output of Calculator Program in C plus plus?

example output of c++ calculator


What is the header for basic input or output in C Plus Plus?

For basic input and output in C++: #include


How can you view page by page output in c plus plus?

Pipe the output to the MORE command.


Input output function in c plus plus?

input is the << operator and output is the >> operator


What is used to output data in c plus plus?

You use output devices or streams, typically console screens, printers and files.


How do you get an output of a c plus plus program to be printed?

See sources and related links below.


Is cin an output identifier in c plus plus?

No. In C++ with <iostream>, cin is a prefedined class that represents stdin, so it is an input identifier.


How can you get c and c plus plus output statements to work together?

The C and C++ library routines for output might, or might not, include use of different buffers. If they are the same buffer (unlikely) then you can simply intermix the techniques. If they are not the same buffer then you need to do a flush sequence between techniques.


What is null printer in c plus plus?

There is no such thing as a null printer in C++. You are perhaps thinking of the null device to which output can be redirected from the command line (effectively hiding the output of a program). However this has nothing whatsoever to do with C++, it is entirely dependant upon the operating system.


What are the basic input and output of c and c plus plus?

That is STANDARD input and STANDARD output. By default, standard input is the keyboard, and standard output is the screen. Standard I/O is set by the operating system, though it may be redirected by script invocation or system commands within the C/C++ program itself. You could, for instance, set standard output to a printer or a file in lieu of a screen. You should also Google Standard Error.


What are file modes in c plus plus?

I guess you mean either input/output/inout/append or binary/text.


Your canon imagerunner 4570 copier states remove paper from output tray?

In Ir 4750 Printout remove by hand