Im currently trying to work with a program that reads raw DV and dumps each frame in the form of a PPM file. I need to read the PPM's into OpenGL Textures and display them. But that is not the problem.

The program has the ability to dump all of the images to stdout instead of the filesystem. I want to read these images through my program's stdin, and this is where my troubles begin.

Does <iostream> directly support this? All example uses of <fstream> that I have seen regard reading/writing a file on the filesystem. How do I read a file from stdin, and to top that, not just one file, but consecutively streaming files to no predictable end (user terminated).

Thanks for any help.

It works with cin and cout too.

// test1.cpp
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
    cout << "Hello World\n";
	return 0;
// test2.cpp
#include <iostream> 
#include <string>
using namespace std;

int main()
    string line;
    cout << "\n\n" << line << "\n";
    return 0;
// command line

D:\dvlp>test2 | test1

Hello World


I understand how piping works, and I have used cin and cout enough to be comfortable with them, but I have always used them in a context similar to what you provided.

When it comes to streaming these files, I am going to have a thread that continuously scans stdin and will need to be reading it in binary mode rather than as text. I have some confusion when it comes to detecting the End Of File, delegating the completed file back to my main thread, and then begin on the next incoming file.

Do I need to actually scan the incoming stream for an EOF indicator, or do the <iostream> functions handle that?

If you know how to do this, and you can post the source, that would be wonderful, but what I am really looking for is a good read on the topic. I have been having problems finding any directly related content.

Treat them as any other stream. So yes, watch for EOF.

Hope this helps.

Ok, so I found this,, and using ...

FILE *stream;

if (argc < 2)
    stream = stdin;
    stream = fopen(argv[i],"r");
    if (stream==NULL) 

So, my program will use 'stream' to fill some buffer. Will stream close automatically when it detects an EOF, or do I need to be scanning the buffer for an EOF? So then, I keep two pointers to the buffer, one for the start of a new file, and one after an EOF is detected. I take that whole chunk, and give it to a program like imagick and it will handle it just like every other image?

Does that sound half right? Am I missing anything? Is there an easier way to do it?


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.