Solved

C++ Printer probs

Posted on 1997-04-13
1
284 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now