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
Post a Comment