Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

C++ Printer probs

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
sutemeier
Asked:
sutemeier
1 Solution
 
mikeblasCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now