Solved

Printing in C++ (USB port)

Posted on 2004-08-24
2
189 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 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.

747 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

11 Experts available now in Live!

Get 1:1 Help Now