Solved

C++ Printer probs

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

708 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

10 Experts available now in Live!

Get 1:1 Help Now