cout according to terminal size

I want to print something like this: "help().............................................Display this help message." to the terminal window.
How can I make it adjust the amount of periods to fit the terminal window dynamically?
There's no standard way of doing it.

On Linux you can use ioctl to get the terminal width.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <iomanip>
#include <sys/ioctl.h>
#include <unistd.h>

int main()
{
	winsize w;
	ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
	std::cout << std::left << std::setw(w.ws_col) << std::setfill('.') << "help()";
}
Last edited on
Topic archived. No new replies allowed.