开发者

Adjusting tab width in C++

Is there any way to adjust tab width开发者_运维知识库 in the console?


It's hard to know until you elaborate more in your question but there's the possibility you just want to write some justified text out to the console, if this is the case you could:

#include <iomanip>

and use:

std::setw

or possibly

std::ios
std::setiosflags
std::resetiosflags

Difficult to know unless you give us more detail in your question...


That's not really a C++ question since the console depends entirely on the underlying environment. For example, I know of no way to do this with the cmd.exe window under Windows.

I thought there may be a way to do this with stty under UNIX-like operating systems but I can't find it after a cursory search.

One possibility is to pass the output through a separate filter program like:

yourprogram | expand --tabs=4

but this is outside the scope of your C++ application.

If you want to be able to do this in C++ portably, you'll probably have to subclass one of the output streams so that you can keep a record of your current column number and translate tab characters into the correct number of spaces.


Try to find GetConsoleWindow() from msdn. And you may refer to http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles6.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜