?
Solved

Printing in C++ (USB port)

Posted on 2004-08-24
2
Medium Priority
?
230 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 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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 …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

752 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