Solved

Printing in C++ (USB port)

Posted on 2004-08-24
2
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 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

Industry Leaders: 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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