⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http:^^www.cs.wisc.edu^~mbirk^cs302^printing_output.html

📁 This data set contains WWW-pages collected from computer science departments of various universities
💻 HTML
字号:
Date: Mon, 11 Nov 1996 17:01:17 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Tue, 01 Oct 1996 20:08:43 GMTContent-length: 4065<html><head><title> Printing Output from Outside the Lab </title></head><body><h2> Printing Output from Outside the Lab </h2>I've had several people ask me about printing the output for their programon a compiler that doesn't support the handy "Print" option in theOutput Window.  If you're trying to do the homeworks from someplace otherthan the lab, and you can't get the output to go the printer, here's myadvice:<h3> Printing from a Unix System </h3>If you're on a Unix system (probably using g++ or CC), use the "script"command if you have it.  It copies all input and output of the programto a file called "typescript" ... then you can simply print the file.Here is an example:<p><pre>/usr/home/jdoe# g++ -o prog1 prog1.cpp/usr/home/jdoe# scriptScript started, file is typescript/usr/home/jdoe# prog1Welcome to John Doe's program ... ... etc .../usr/home/jdoe# exitScript done, file is typescript/usr/home/jdoe# lpr -Pmylaser typescript</pre><p>Warning: If you use the script command, don't forget to type exit when youare done!  And don't "nest" script commands.<h3> Printing from a DOS (non-Windows) System </h3>If you're on a DOS system (not running Windows), you can redirect the outputof your program to a file.  For example, if you've compiled your programinto an executable called PROG1.EXE, you can redirect the output toa file "output.txt" using the following DOS command:<pre>   prog1 >output.txt</pre>Also, you can "append" the output of your program to a previous run withtwo greater-than signs:<pre>   prog1 >>output.txt</pre><p>This has two disadvantages, however.  First, since the output is going toa file, you can't see it on the screen!  So you have to "know" what theexpected input is beforehand.  Second, the input you type is not redirectedto the file.  Thus you need to modify your program to "echo" the inputso that it appears in the file too.  For example:<p><pre>#include &lt;iostream.h&gt;int main (){   int num_apples;   cout &lt;&lt; "How many apples do you want?";   cin &gt;&gt; num_apples;   cout &lt;&lt; num_apples &lt;&lt; endl; // ECHO INPUT FOR REDIRECTION   return 0;}</pre><h3> Printing on Any System </h3>If you're printing from any other system that doesn't have a "Print Output"command or doesn't support redirection, you can use the following techinque.This should work on any system: Windows, Mac, Unix, etc.<p>The idea is to modify the program so that all the output goes to a fileinstead of a screen.  Thus this method suffers the same problems as theDOS method above: output is not displayed on the screen (i.e. you can'tsee the prompts) and input is not redirected to the file (thus you haveto echo the input in your program).  For example, consider the followingprogram:<p><pre>#include &lt;iostream.h&gt;int main (){   int num_apples;   cout &lt;&lt; "How many apples do you want?";   cin &gt;&gt; num_apples;   return 0;}</pre><p>To make this program's input and output go to a file named "output.txt",we could modify it like this (note the extra <tt>#include</tt> directive):<pre>#include &lt;iostream.h&gt;#include &lt;fstream.h&gt;int main (){   ofstream fout = "output.txt";  // Open a file for writing   cout = fout;                   // Redirect cout to the file   int num_apples;   cout &lt;&lt; "How many apples do you want?";   cin &gt;&gt; num_apples;   cout &lt;&lt; num_apples &lt;&lt; endl;    // Echo input for redirection   return 0;}</pre><p>Once you have the program's output saved in a file, you can use almostany means to print that file out.  Under Windows you can use the Notepad,for example.<h3> If All Else Fails </h3>If, for some reason, all of the above methods fail for you (the last one_should_ work), you will have to print the output from the Vectra lab.Put the source code on a floppy disk, go to the lab, compile the program,and print the output.<hr><i><a href="mailto:mbirk@cs.wisc.edu">mbirk@cs.wisc.edu</a></i></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -