Solved

C++ Printer probs

Posted on 1997-04-13
1
295 Views
Last Modified: 2008-03-17
I am learning C++, coming from K&R C.  I have the follwoing snipet of code that won't work properly.  Maybe you can assist.

#include <fstream.h>
#include <process.h>

ofstream printer;

printer.open("PRN");

char onechar;

printer << "This is the beginning."
        << '\f'
        << flush;

//print file

Wont't print to the printer.  What is wrong?  

Thanks.

jim

0
Comment
Question by:sutemeier
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 1162694
I made your code snippet into a program, and it compiled and printed just fine for me.  I use Visual C++ 5.0 under Windows 95.  Here's the program that I ended up using:

#include <fstream.h>
#include <process.h>

void main()
{
   ofstream printer;

   printer.open( "PRN");
   char onechar;

   printer << "This is the beginning."
      << '\f'
      << flush;
}

Maybe your call to open() is failing.  You can try to see if it worked by calling the rdstate() or bad() members of your printer object.

.B ekiM
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question