Looking for a more efficient way to generate/print a "progress bar" in C++
<p>I am working on some grid generation code, during which I really want to see where I am, so I download a piece of progress bar code from internet and then inserted it into my code, something like:</p>

<pre><code>std::string bar;

for(int i = 0; i &lt; 50; i++)
{
    if( i &lt; (percent/2))
    {
        bar.replace(i,1,"=");
    }
    else if( i == (percent/2))
    {
        bar.replace(i,1,"&gt;");
    }
    else
    {
        bar.replace(i,1," ");
    }
}

std::cout&lt;&lt; "\r" "[" &lt;&lt; bar &lt;&lt; "] ";
std::cout.width( 3 );
std::cout&lt;&lt; percent &lt;&lt; "%     "
    &lt;&lt; " ieration: " &lt;&lt; iterationCycle &lt;&lt; std::flush;
</code></pre>

<p>This is very straightforward. However, it GREATLY slows down the whole process, note <code>percent=iterI/nIter</code>.</p>

<p>I am really get annoyed with this, I am wondering if there is any smarter and more efficient way to print a progress bar to the screen.</p>

<p>Thanks a million.</p>
