Solved

C++ Printer probs

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

777 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