この質問は私が最近入ったバグから来ています。私は16進数としてファイルにいくつかの整数値を保存しようとしていた。例として、これは私が何をすべきかです:cout << std :: ios :: hex doとは何ですか?
cout << std::hex << value << endl; // (1)
しかし誤って、私は次のようにそれを使用する:
cout << std::ios::hex << value << endl; // (2)
コンパイラは文句はありませんが、明らかに結果が正しくありません。ランダムに2つ以上の値を試していましたが、実際には部分的に正しい結果が得られますが、という接頭辞が付いているようです。私はがどこから来ているのか分かりません。どこにでも良い参考文献はありません。フードの下で何が起きているのか誰でも説明できますか?
cout << std::hex << 255 << endl; // output: FF
cout << std::ios::hex << 255 << endl; // output: 800ff
cout << std::hex << 135 << endl; // output: 87
cout << std::ios::hex << 135 << endl; // output: 80087
cout << std::hex << 11 << endl; // output: b
cout << std::ios::hex << 11 << endl; // output: 800b