C++相談室 part44
■ このスレッドは過去ログ倉庫に格納されています
0085デフォルトの名無しさん
2005/10/09(日) 02:57:05禿げしく遅いけど。boost::format当たりに何かいいのがあると思う。
#include <iostream>
#include <fstream>
class Binary {
int x, y;
public:
Binary(int i = 0, int j = 0) : x(i), y(j) {}
int getx() const { return x; }
int gety() const { return y; }
};
std::ostream& operator<<(std::ostream& os, const Binary& bin)
{
const int x = bin.getx();
for (int i = 0; i < bin.gety(); i++)
if (!os.put(reinterpret_cast<const char*>(&x)[i]))
return os;
return os;
}
int main()
{
std::ofstream test("test.bin", std::ios::out | std::ios::binary);
test << Binary(84, 4);
}
■ このスレッドは過去ログ倉庫に格納されています