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 | [email protected] | http://dirk.eddelbuettel.com
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to