<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Progressbar in der Konsole]]></title><description><![CDATA[<p>Erstmal allen eine guten Morgen!</p>
<p>Ich hab mich mal drangesetzt eine Progressbar zu schreiben.<br />
Ich hab nur das Problem, dass diese sehr aufwendig ist und die Laufzeit des Programms erheblich verlängert wird.</p>
<p>Hier erstmal mein Codefragment:</p>
<pre><code class="language-cpp">void makeBaum(Knoten **wurzel)
{
    char buffer[60];   //buffer für progressbar
    buffer[0]='[';
    for(int i=1; i&lt;51; i++)
        buffer[i]=' ';
    buffer[51]=']';
    buffer[52]=' ';
    buffer[53]=' ';
    buffer[54]=' ';
    buffer[55]=' ';
    buffer[56]='0';
    buffer[57]=' ';
    buffer[58]='%';
    buffer[59]='\0';
    long int x=GRAD/50; //Grad=1000000
    long int a=1;       //anzahl der eingefuegten elemente
    int y=1;            //index für buffer
    int k=0;            //hilfsvariable für %
    int z=0;            //hilfsvariable für %
    time_t t;
    time(&amp;t);
    srand(static_cast&lt;unsigned int&gt;(t));
    for(long int i=0; i&lt;GRAD; i++)
    {

        einfuegen(wurzel,rand()%UINT_MAX+1);

#ifdef PROGRESSBAR
        for(int j=sizeof(buffer)-1; j&gt;=0; j--)
            cout &lt;&lt; &quot;\b&quot;;
        cout &lt;&lt; buffer;
        a++;
        if(a==x/2)
            k++;
        else if(a==x)
        {
            buffer[y]='#';
            y++;
            k++;
            a=0;
            if(k==10)
            {
                z++;
                k=0;
                buffer[55]=z+'0';
                buffer[56]=k+'0';
                if(z==10)
                {
                    buffer[54]='1';
                    buffer[55]='0';
                    buffer[56]='0';
                }

            }
            else
                buffer[56]=k+'0';
        }
		else;

#endif
    }
}
</code></pre>
<p>Vielleicht habt Ihr ein paar Verbesserungsvorschläge für mich, was die Laufzeit erheblich verringert?!</p>
<p>MfG<br />
Sfuccma</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/268029/progressbar-in-der-konsole</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 04:03:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/268029.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Jun 2010 06:17:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Progressbar in der Konsole on Thu, 03 Jun 2010 06:17:08 GMT]]></title><description><![CDATA[<p>Erstmal allen eine guten Morgen!</p>
<p>Ich hab mich mal drangesetzt eine Progressbar zu schreiben.<br />
Ich hab nur das Problem, dass diese sehr aufwendig ist und die Laufzeit des Programms erheblich verlängert wird.</p>
<p>Hier erstmal mein Codefragment:</p>
<pre><code class="language-cpp">void makeBaum(Knoten **wurzel)
{
    char buffer[60];   //buffer für progressbar
    buffer[0]='[';
    for(int i=1; i&lt;51; i++)
        buffer[i]=' ';
    buffer[51]=']';
    buffer[52]=' ';
    buffer[53]=' ';
    buffer[54]=' ';
    buffer[55]=' ';
    buffer[56]='0';
    buffer[57]=' ';
    buffer[58]='%';
    buffer[59]='\0';
    long int x=GRAD/50; //Grad=1000000
    long int a=1;       //anzahl der eingefuegten elemente
    int y=1;            //index für buffer
    int k=0;            //hilfsvariable für %
    int z=0;            //hilfsvariable für %
    time_t t;
    time(&amp;t);
    srand(static_cast&lt;unsigned int&gt;(t));
    for(long int i=0; i&lt;GRAD; i++)
    {

        einfuegen(wurzel,rand()%UINT_MAX+1);

#ifdef PROGRESSBAR
        for(int j=sizeof(buffer)-1; j&gt;=0; j--)
            cout &lt;&lt; &quot;\b&quot;;
        cout &lt;&lt; buffer;
        a++;
        if(a==x/2)
            k++;
        else if(a==x)
        {
            buffer[y]='#';
            y++;
            k++;
            a=0;
            if(k==10)
            {
                z++;
                k=0;
                buffer[55]=z+'0';
                buffer[56]=k+'0';
                if(z==10)
                {
                    buffer[54]='1';
                    buffer[55]='0';
                    buffer[56]='0';
                }

            }
            else
                buffer[56]=k+'0';
        }
		else;

#endif
    }
}
</code></pre>
<p>Vielleicht habt Ihr ein paar Verbesserungsvorschläge für mich, was die Laufzeit erheblich verringert?!</p>
<p>MfG<br />
Sfuccma</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906166</guid><dc:creator><![CDATA[sfuccma]]></dc:creator><pubDate>Thu, 03 Jun 2010 06:17:08 GMT</pubDate></item><item><title><![CDATA[Reply to Progressbar in der Konsole on Thu, 03 Jun 2010 07:17:03 GMT]]></title><description><![CDATA[<p>Sowas stumpfes?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;

class ProgressBar
{
public:
  ProgressBar(unsigned int fSteps, 
	      unsigned int fWidth) : steps(fSteps), current(0), width(fWidth)
  {

  }

  void step(int fValue = 1)
  {
    current += fValue;
    if (current &gt; steps) current = steps;
    if (current &lt;     0) current = 0;
  }

  friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const ProgressBar&amp;);

private:
  unsigned int steps;
  unsigned int current;

  unsigned int width;

};

std::ostream &amp;operator&lt;&lt;(std::ostream &amp;str, const ProgressBar &amp;bar)
{
  int aPos = (bar.width / bar.steps) * bar.current;
  str &lt;&lt; &quot;[&quot;;
  for(int i = 0; i &lt; bar.width; i++)
    str &lt;&lt; (i &lt;= aPos ? '#' : ' ');
  str &lt;&lt; &quot;] &quot;;

  str &lt;&lt; std::setw(3) &lt;&lt; static_cast&lt;int&gt;((bar.current / static_cast&lt;double&gt;(bar.steps))*100) &lt;&lt; &quot;%&quot;;

  return str;
}

int main(int argc, char* argv)
{

  ProgressBar bar(100,100);

  for(int i = 0; i &lt; 100; i++)
    {
      bar.step();
      std::cout &lt;&lt; bar &lt;&lt; std::endl;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1906178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906178</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Thu, 03 Jun 2010 07:17:03 GMT</pubDate></item><item><title><![CDATA[Reply to Progressbar in der Konsole on Thu, 03 Jun 2010 08:41:40 GMT]]></title><description><![CDATA[<p>Hier was zum abkupfern:<br />
<a href="http://www.boost.org/doc/libs/1_43_0/libs/timer/timer.htm#Class%20progress_display" rel="nofollow">http://www.boost.org/doc/libs/1_43_0/libs/timer/timer.htm#Class progress_display</a></p>
<p>Man sollte aber bedenken, dass Ausgaben auf der Konsole im Vergleich zu anderen Operationen sehr langsam sein können.<br />
Bei zeitkritischen Berechnungen würde ich es also nicht übertreiben mit Ausgaben, die man vielliecht sowieso nicht lesen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906198</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Thu, 03 Jun 2010 08:41:40 GMT</pubDate></item></channel></rss>