ok!!! got it finally.
Thank you all for your attention.
The file stream doesn't need to be buffered (or is it already? I'm still confused about that...)
Here is a working code example for who's interested:
(last question: would it be portable?)
Code:
//stdin.cpp
#include <iostream>
using namespace std;
bool checkifdata (FILE *f)
{
int fno = fileno (f);
fd_set fdset;
FD_ZERO (&fdset); // note: fdset must be referenced here and below
FD_SET (fno, &fdset);
return select (fno + 1, &fdset, NULL, NULL, NULL);
}
int main ()
{
FILE *f = fopen ("temp.txt", "r");
time_t timer = time (NULL);
char input;
while (1) {
// this just simulates my working server
if ((time (NULL) - timer) >= 1) {
timer = time (NULL);
cout << ".\n";
}
if (checkifdata (f)) {
input = fgetc (f); // read next char
if (input != -1) cout << input; // print it if not EOF
}
}
fclose (f);
return 0;
}
Code:
terminal 1:
$ g++ -o stdin stdin.cpp
$ ./stdin
terminal 2:
$ cat >> temp.txt