473,287 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Reading from standard in

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();
Jul 22 '05 #1
3 2785
"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
Jul 22 '05 #2
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

Jul 22 '05 #3
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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
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: --------
1
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...
6
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);
6
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...
29
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...
7
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!
21
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...
3
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>
41
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 ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.