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

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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -