U
ultr
Hello,
I was looking for a solution on http://www.cplusplus.com/ and serched
groups, but cannot find anything interesting.
My program opens an input file stream:
ifstream f( "in.txt" );
then goes to its end:
f.seekg( 0, ios_base::end );
and then, in a loop, waits for a new line to be put into this file,
and reads it:
string line;
while( true )
{
f.clear();
if( f.peek() != EOF )
{
getline( f, line );
cout << "> " << line << "\n";
}
usleep( 50000 );
}
However the file in.txt may be renamed or deleted, and a new, empty
one may be created in its place.
How can I detect it and close the current stream, and reopen it with
the new in.txt file?
Thank you.
Piotr D±browski
I was looking for a solution on http://www.cplusplus.com/ and serched
groups, but cannot find anything interesting.
My program opens an input file stream:
ifstream f( "in.txt" );
then goes to its end:
f.seekg( 0, ios_base::end );
and then, in a loop, waits for a new line to be put into this file,
and reads it:
string line;
while( true )
{
f.clear();
if( f.peek() != EOF )
{
getline( f, line );
cout << "> " << line << "\n";
}
usleep( 50000 );
}
However the file in.txt may be renamed or deleted, and a new, empty
one may be created in its place.
How can I detect it and close the current stream, and reopen it with
the new in.txt file?
Thank you.
Piotr D±browski