I need to read from a growing file in C++, and found this page - How to read a growing text file in C++?. I tested the Answer from there posted by @hmjd. For testing purpose, I wrote a simple c++ code to read a large file and then write it to file every 0.3 seconds so that the file will be growing. In the meantime, while the growing file was generating, I used hmjd's code to test reading it. The first answer staring with if(ifs.seekg(p)) does not work at all, and the second answer starting with 'if(ifs.is_open())' works, but the loop will never end.
            Asked
            
        
        
            Active
            
        
            Viewed 194 times
        
    0
            
            
        - 
                    4Show us your code for reading the file or relax and let us enter your brain with our psychic powers .... – Thomas Matthews Aug 12 '15 at 22:57
 - 
                    Did you look at the answers for that question, or just use the code from the question? – Wug Aug 13 '15 at 00:04
 - 
                    I added my solution to the answers of the question you linked: http://stackoverflow.com/a/31977550/3807729 – Galik Aug 13 '15 at 00:22
 - 
                    @Galik Thank you so much, this is a better version with 'seekg' and 'tellg'. It works as the same behavior as what hmjd provided, after the growing file stop growing, your code hangs. – user3658306 Aug 13 '15 at 20:06
 
1 Answers
0
            
            
        This might be overly simplified, but couldn't you just close your handle to the file after it's grown and reopen a new file descriptor?
        Tony Tyrrell
        
- 131
 - 1
 - 7