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

时间:2016-06-21 15:25:52

标签: c++11 output header-files

这是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 << "\033[" << static_cast<int>(value) << "m"
               : os;
}
}

实际上这是一个仅用于制作彩色控制台的标题库。我尝试将此项目编译为具有C ++ 11支持的控制台应用程序,但输出是意外的。输出结果如何?

1 个答案:

答案 0 :(得分:2)

输出结果表明color.hpp取决于正在解释特殊&#34;逃避&#34;输出代码,但您的终端不解释这些代码。

这不是标准的C ++,BTW。