cout according to terminal size

Jul 3, 2017 at 5:36pm
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?
Jul 3, 2017 at 8:52pm
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 Jul 3, 2017 at 8:55pm
Topic archived. No new replies allowed.