2016-06-21 6 views
0

ouptutコンソール、これはsource.cpp←[0メートル←[42メートル←[37mIf

#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サポートのコンソールアプリケーションとしてコンパイルしようとしましたが、出力は予期せぬものでした。出力は何を示唆していますか?

答えて

2

出力では、特別な「エスケープ」出力コードを解釈している端末によって異なりますが、端末ではこれらのコードが解釈されないことが示唆されています。

これは標準のC++ではなく、BTWです。

+0

それは何ですか? – dlpsankhla

+0

@dlpsankhla C++には、あなたが持っている端末の種類と、あなたの出力をどのように解釈するかという概念はありません。同等のアナウンスは、テキストエディタでスプレッドシートファイルを開くことです。データは表示できますが、テキストエディタはデータを解釈せずに行と列として表示します。 http://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequencesまたはhttp://stackoverflow.com/questions/2294281/howを探している可能性があります。 -to-recognisation-ansi-color-escape-codes-in-windows7-64-bit-command-terminal –

+0

@dlpsankhla Windows 10を使用している場合、サポートが組み込まれています。これもチェックしてください:http://www.nivot.org/blog/post/2016/02/04/Windows-10-TH2-%28v1511%29-Console-Host-Enhancements –

関連する問題