Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8802901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:12:04+00:00 2026-06-14T01:12:04+00:00

I recently implemented a progress bar class in C++. I wrote something like cout

  • 0

I recently implemented a progress bar class in C++. I wrote something like

cout << "\r" << percentage_done << "%" << flush;

Now I am running some programs piping the output to less.
The problem is that less shows me a lot of lines of the type

^M1%^M2%…

So the “\r” is not interpreted correctly. Is it possible to pipe this in such a way
that less will only show the final 100% line or do I have to add a switch to my program
to disable the progression bars entirely?

I have the same problem when I pipe the output directly to a file, so the output files
occupy a lot of disk space unnecessarily.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:12:05+00:00Added an answer on June 14, 2026 at 1:12 am

    Well, I think that it was quite right what Jan Hudec said. I wrote myself a small function

    #include <unistd.h>
    
    bool stdout_has_terminal()
    {
      return NULL != ttyname(STDOUT_FILENO);
    }
    

    Depending on the return value I either print the progression bar or not. Now everything works quite nicely 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently implemented a class like: class TestClass : IDisposable { RegistryKey m_key; public
Interesting problem I ran into recently: I implemented a Stream class (a wrapping stream
I've recently implemented the ajax comet upload with progress found here: https://github.com/mbk/ajaxupload_with_comet When compiling
I've recently implemented a singleton class, and within it I've declared a static generic
I have recently implemented something in a rails application that allows me to read
I recently implemented a quick T4 template to generate some data access related classes
I've recently implemented some vectored exception handling to catch errors in our software. This
I'm a complete newbie in the computer vision world and recently I implemented some
I have recently implemented an MVC3 website and had to now include data from
I recently implemented Java 7's WatchService and it works perfectly. Now I wondered if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.