Hi all,
I suppose some of you know the program Redmon (type redmon in google, first
result). This neat little tool allows to hook up any functionality to a
printer by putting the file printed to the printer to standard in.
You have to provide yourself the program that does something with that data,
so I thought with some quick c/c++ programming that would be no problem. I
tried dozens of ways of reading the data from stdin or cin, char by char
(like sample below), buffers... but I only got it working for text files,
e.g. pdf-files, html-files,...
When a gif or any other binary file is sent to it, the none of the ways
would work: in case of byte by byte reading it stops way too early (example
1), in case of buffered reading (example 2), it only goes through the buffer
1 time, like if he already encountered eof.
I know in case of binary files this is perfectly possible, but how to read
then binary data from the standard input?
A hint, url, some names of methods to be used, are fine. I am no noobie...
Regards,
Olivier
//example 1
ofstream logfile(fileName.c_str(), ios::binary | ios::out);
char c;
cin.get(c);
while (!cin.eof())
{
logfile << c;
cin.get(c);
}
logfile.close();
//example2
char *buffer = new char[1000];
ofstream outputfile(filenameTmp->c_str(), ios::out);
while ( !cin.eof() )
{
cin.read(buffer, 1000);
outputfile.write(buffer, 1000);
}
outputfile.close(); 3 2793
"Olivier Maurice" <ol*************@skynet.be> wrote in message
news:41***********************@news.skynet.be... Hi all,
I suppose some of you know the program Redmon (type redmon in google,
first result). This neat little tool allows to hook up any functionality to a printer by putting the file printed to the printer to standard in.
You have to provide yourself the program that does something with that
data, so I thought with some quick c/c++ programming that would be no problem. I tried dozens of ways of reading the data from stdin or cin, char by char (like sample below), buffers... but I only got it working for text files, e.g. pdf-files, html-files,... When a gif or any other binary file is sent to it, the none of the ways would work: in case of byte by byte reading it stops way too early
(example 1), in case of buffered reading (example 2), it only goes through the
buffer 1 time, like if he already encountered eof.
I know in case of binary files this is perfectly possible, but how to read then binary data from the standard input?
A hint, url, some names of methods to be used, are fine. I am no noobie...
Have you consulted the FAQ ( http://www.parashift.com/c++-faq-lite/) setion
15 ("Input/output via <iostream> and <cstdio>") question 13 ("How can I
"reopen" std::cin and std::cout in binary mode?")?
--
David Hilsee
I am afraid I will need a little more hint or help :-). This is some great
resource though. Thanks already. Have you consulted the FAQ (http://www.parashift.com/c++-faq-lite/) setion 15 ("Input/output via <iostream> and <cstdio>") question 13 ("How can I "reopen" std::cin and std::cout in binary mode?")?
-- David Hilsee
Olivier Maurice wrote: I am afraid I will need a little more hint or help :-). This is some great resource though. Thanks already.
OK.
The FAQ clearly says:
There is no standard way to do it. It all depends on your compiler/platform.
Thus: You need to ask in a newsgroup which discusses your compiler and/or platform.
comp.lang.c++ deals with platform independent ascpects of C++ only.
--
Karl Heinz Buchegger, GASCAD GmbH
Teichstrasse 2
A-4595 Waldneukirchen
Tel ++43/7258/7545-0 Fax ++43/7258/7545-99
email: kb******@gascad.at Web: www.gascad.com
Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Santah |
last post by:
hi
I'm new to C++
and I'm currently working on Visual C++ 6.0
I'm trying to open a text file, and read some data from it
part of the text file looks like this:
--------
|
by: fabrice |
last post by:
Hello,
I've got trouble reading a text file (event viewer dump) by using the
getline() function...
After 200 - 300 lines that are read correctly, it suddenly stops
reading the rest of the...
|
by: Gus Tabares |
last post by:
Hello,
I'm having trouble reading in a character. Here is a snippet of code:
int num;
char character;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered %d.\n", num);
|
by: KevinD |
last post by:
assumption: I am new to C and old to COBOL
I have been reading a lot (self teaching) but something is not sinking
in with respect to reading a simple file - one record at a time.
Using C, I am...
|
by: yourmycaffiene |
last post by:
Okay, this if my first post so go easy on me plus I've only been using
C for a couple of weeks. I'm working on a program currently that
requires me to read data from a .dat file into a 2d array and...
|
by: Bo Yang |
last post by:
Hi,
I am now reading the C++ standard, and have some troubles.
What is unqualified name and what is qualified name?
I found the standard is too hard for non-english programmer!
|
by: Stephen.Schoenberger |
last post by:
Hello,
My C is a bit rusty (.NET programmer normally but need to do this in
C) and I need to read in a text file that is setup as a table. The
general form of the file is
00000000 USNIST00Z...
|
by: NaN |
last post by:
Hi I'm using Dev-C++.
Here is my sourcecode.
/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/
#include <conio.h>
|
by: biplab |
last post by:
Hi all,
I want to read the pixel values of a .bmp image(which will be input to
the code) into a matrix...plz help me out as i can not understand how
to achieve this...
thanks in advance
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |