我正在使用 ANSI 颜色代码在 Unix 控制台中格式化我的输出。
const auto& getCode(Color mColor)
{
static std::map<Color, std::string> codes;
// ...
return codes[mColor]
}
cout << getCode(Color::Red) << "red text";
但是,当使用std::setw
或等操纵器std::left
时,结果会受到颜色代码的影响,因为它是一堆字符。
我应该如何处理这个问题?有没有办法让流操纵器忽略颜色代码?