How to fstream parse file in stream?

What do I have to do to create a live stream from a file (log.txt) where the log file is still filling.

1
2
3
4
  ifstream file("C:\\Users\\user\\Desktop\\log.txt")

while(){
}
simply hold the fstream instance alive and dont close your file
You can simply put i.e. keep file open and don't close it.
1
2
3
4
5
6
7
8
9

 ifstream file("C:\\Users\\user\\Desktop\\log.txt")

while(file.is_open())
{


}
When you get to the end of the stream, pause for a second or two, then clear the stream and try again. Here is code that reads words from cin and prints them out, one per line. It also says when it's sleeping. This uses the UNIX sleep() call, which might not be available on your system:

1
2
3
4
5
6
7
8
9
10
11
12
13
    string str;
    while (true) {
	if (cin >> str) {
	    cout << str << '\n';
	} else if (cin.eof()) {
	    cout << "sleeping...\n";
	    cin.clear();
	    sleep(5);
	} else {
	    cout << "some other error\n";
	    break;
	}
    }
Topic archived. No new replies allowed.