how to redirect the std out immediately to a file in C++ or python? -


in c++, have code:

#include <unistd.h> #include <iostream> using namespace std; int main() {   cout<<"before-sleep"<<endl;   sleep(5);   cout<<"after-sleep"<<endl;   return 1; }  

then compile g++ main.exe , run it. when run redirect std out file :

./main.exe > file.log 

however, 2 line "before-sleep" , "after-sleep" print file @ same time -- have 5s delay. how can made first line print file , second line print file 5s delay?

the situation same in python:

import time print 'before sleep' time.sleep(5) print 'after sleep' 


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -