[Rcpp-devel] progress bar in for loop
Dirk Eddelbuettel
edd at debian.org
Sun Aug 8 17:06:59 CEST 2010
On 8 August 2010 at 16:37, baptiste auguie wrote:
| Dear list,
|
| There's one feature that I miss after porting a for loop from R to C++
| : the possibility to add a progress bar. I used to write,
|
| library(plyr)
| l_ply(seq(1,10), function(ii) Sys.sleep(0.2), .progress = "text")
|
| My naive attempt in C++ was unsuccessful,
|
| using namespace std;
|
| cout << "["; //start progress bar
| for(ll=0; ll<N; ll++){ // loop over some variable
| if ( !( ((ll+1)*100/N) % 5) ) // display a character every 5 steps
| cout << "=";
| }
| cout << "["; //stop progress bar
|
| For some reason (compiler?) nothing is displayed until the end of the
| execution, where the full text is suddenly displayed at once. Is there
| a workaround?
Output is buffered. Try this
cout << "=" << std::flush;
and see if it helps.
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list