[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Printing in C++ (USB port)

Posted on 2004-08-24
2
Medium Priority
?
244 Views
Last Modified: 2006-11-17
hello experts,

I am outputing the follwoing info to screen in the following format,

i need to send it to printer to print, how do i go about printing.

cout << setiosflags(ios::left)<<setw(5)<<AccountNumber<< setw(28)<<name;
cout << setw(17)<<Curr<<setw(12)<<calcu<<setw(8)<<code;

PS:This is my first attempt to print in c++ so i do not have a clue, please explain everything and if code can be provided would be great.

Thank you.
0
Comment
Question by:claracruz
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 11884899
You coult just attach 'lpt1:' to your 'cout' object, e.g.

int fd = _open ( "lpt1:", _O_TEXT | _O_WRONLY);
cout.attach ( fd);

cout << setiosflags(ios::left)<<setw(5)<<AccountNumber<< setw(28)<<name;
cout << setw(17)<<Curr<<setw(12)<<calcu<<setw(8)<<code;

Or, leave cout alone and use

ofstream prn;

int fd = _open ( "lpt1:", _O_TEXT | _O_WRONLY);
prn.attach ( fd);

prn << setiosflags(ios::left)<<setw(5)<<AccountNumber<< setw(28)<<name;
prn << setw(17)<<Curr<<setw(12)<<calcu<<setw(8)<<code;
0
 
LVL 86

Expert Comment

by:jkr
ID: 11888670
Oh, and don't forget to

_close( fd);

when it is no longer needed. Speaking of that, you need to add

#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 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.
Suggested Courses

834 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