←[0m←[42m←[37mIf在控制台输出

←[0m←[42m←[37mIf in the console output

这是source.cpp

#include "color.hpp"
#include<conio.h>
int main()
{
    std::cout << std::endl
              << color::style::reset << color::bg::green << color::fg::gray
              << "If you're seeing green bg, then color works!"
              << color::style::reset << std::endl;
    _getch();
    return 0;
}

这是来自 color.hpp 的代码片段:

template <typename T>
using enable = typename std::enable_if
    <
        std::is_same<T, color::style>::value ||
        std::is_same<T, color::fg>::value ||
        std::is_same<T, color::bg>::value ||
        std::is_same<T, color::fgB>::value ||
        std::is_same<T, color::bgB>::value,
        std::ostream &
    >::type;

template <typename T>
inline enable<T> operator<<(std::ostream &os, T const value)
{
    std::streambuf const *osbuf = os.rdbuf();
    return ((supportsColor()) && (isTerminal(osbuf)))
               ? os << "3[" << static_cast<int>(value) << "m"
               : os;
}
}

实际上这是一个 header 唯一的用于制作彩色控制台的库。我试图将此项目编译为支持 C++11 的控制台应用程序,但输出是意外的。输出提示什么?

输出表明 color.hpp 依赖于解释特殊 "escape" 输出代码的终端,但您的终端不解释这些代码。

这不是标准的 C++,顺便说一句。