G
garyatusa
Hi, there,
I need to put a bunch of data to an iostream, or a buffer sequencially
for each object, and write them to a file in specific sequence. I
couldn't find any helpful information how to do that. If iostream is
not the best way, how to do it. I don't know the size of the object.
Your time and help are highly appreciated. Following is the structure
stripped off unnecessary parts:
class Base
{
int length;
virtual void Read();
virtual void Write();
};
class D1 : public Base
{
streambuf* m_stream; // or iostream, which one is better?
};
void D1::Read()
{
m_stream = new iostream();
streampos start = m_stream->tellp();
for (int i = 0; i < 10; i++) //write some data to the buffer
m_stream->put(i);
streampos end = m_stream->tellp();
CheckWhatWeWrite(m_stream, start, end); //suppose we need to check
}
void D1::Write(ofstream* fOut)
{
//fOut->rdbuf(m_stream); ??? //I need to append this to fOut, which
function should use?
}
Thanks lot in advance!
I need to put a bunch of data to an iostream, or a buffer sequencially
for each object, and write them to a file in specific sequence. I
couldn't find any helpful information how to do that. If iostream is
not the best way, how to do it. I don't know the size of the object.
Your time and help are highly appreciated. Following is the structure
stripped off unnecessary parts:
class Base
{
int length;
virtual void Read();
virtual void Write();
};
class D1 : public Base
{
streambuf* m_stream; // or iostream, which one is better?
};
void D1::Read()
{
m_stream = new iostream();
streampos start = m_stream->tellp();
for (int i = 0; i < 10; i++) //write some data to the buffer
m_stream->put(i);
streampos end = m_stream->tellp();
CheckWhatWeWrite(m_stream, start, end); //suppose we need to check
}
void D1::Write(ofstream* fOut)
{
//fOut->rdbuf(m_stream); ??? //I need to append this to fOut, which
function should use?
}
Thanks lot in advance!