Solved

Printing in C++ (USB port)

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

Suggested Solutions

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. …
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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