سؤال

In my program I would like to display status messages like so

Checking system               [OK]
Loading required files        [OK]
...

But right now its comes like the following when I use \t

Checking system        [OK]
Loading required files        [OK]

I tried setw but it comes like (probably because of bad implementation)

           Checking system[OK]
    Loading required files[OK]

So is there a way I can format the output WITHOUT using any external libraries (ie, no ncurses etc)

Also note that the size of the output terminal is known.

هل كانت مفيدة؟

المحلول

You can use std::left to display a string left-justified in a specified width of field:

std::cout << std::left << std::setw(30) << "Checking system";
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top