| | |
Read Files From stdin
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 45
Reputation:
Solved Threads: 0
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.
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.
C++ Syntax (Toggle Plain Text)
// test1.cpp #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout << "Hello World\n"; return 0; }
C++ Syntax (Toggle Plain Text)
// test2.cpp #include <iostream> #include <string> using namespace std; int main() { string line; getline(cin,line); cout << "\n\n" << line << "\n"; return 0; }
C++ Syntax (Toggle Plain Text)
// command line D:\dvlp>test2 | test1 Hello World D:\dvlp>
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: May 2006
Posts: 45
Reputation:
Solved Threads: 0
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.
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.
Last edited by petzoldt01; May 23rd, 2008 at 5:17 pm.
•
•
Join Date: May 2006
Posts: 45
Reputation:
Solved Threads: 0
Ok, so I found this, http://www.daniweb.com/forums/thread45686.html, and using ...
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?
Thanks
C++ Syntax (Toggle Plain Text)
FILE *stream; if (argc < 2) { stream = stdin; } else { 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?
Thanks
![]() |
Similar Threads
- functions in header files (C++)
- problem with stdin (Python)
- static variable (C)
- Files in C (C)
- validating input problem (C)
- Can Someone please check my project & comment/tips (C)
- Reading Binary files via stdin (C++)
- Pointers (C++)
- Multithreading problem (C)
- Linux Audio Streaming (live!) using Ices and Icecast (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Function wont accept my vector by reference?
- Next Thread: Stacks ERROR
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






