zero termination for BYTE?
-
Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:
char* buf = new char[128];
sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );m_oStream3.open(buf, ios::out|ios::binary);
if( !m_oStream3 )
{
// ...
}for( int i = 0; i < 12; i++ )
{
m_oStream3 << header[i];
}m_oStream3 << data; // data == 1 BYTE
m_oStream3.flush();
m_oStream3.close();delete [] buf;
This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift
-
Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:
char* buf = new char[128];
sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );m_oStream3.open(buf, ios::out|ios::binary);
if( !m_oStream3 )
{
// ...
}for( int i = 0; i < 12; i++ )
{
m_oStream3 << header[i];
}m_oStream3 << data; // data == 1 BYTE
m_oStream3.flush();
m_oStream3.close();delete [] buf;
This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift
Souldrift wrote:
when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be?
No to both. NULL-termination is merely a C convention for the representation of strings.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:
char* buf = new char[128];
sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );m_oStream3.open(buf, ios::out|ios::binary);
if( !m_oStream3 )
{
// ...
}for( int i = 0; i < 12; i++ )
{
m_oStream3 << header[i];
}m_oStream3 << data; // data == 1 BYTE
m_oStream3.flush();
m_oStream3.close();delete [] buf;
This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift
Souldrift wrote:
Do BYTE streams generally have to be?
Short answer is no. Since it is your application it is your decision. The only thing to bear in mind is that the program that reads the file needs to understand, and use, the same format rules as the program that writes it.
-
Hi there, this might be a slightly stupid question, but when I write a single BYTE into a file (using ofstream), does it need to be null-terminated? Do BYTE streams generally have to be? Example code:
char* buf = new char[128];
sprintf_s( buf, 128, "TestOutput/RTPEngineBin%04d.out", m_iFileCount );m_oStream3.open(buf, ios::out|ios::binary);
if( !m_oStream3 )
{
// ...
}for( int i = 0; i < 12; i++ )
{
m_oStream3 << header[i];
}m_oStream3 << data; // data == 1 BYTE
m_oStream3.flush();
m_oStream3.close();delete [] buf;
This is a small rtp package. Header has 12 bytes and the payload is just a single byte. Cheers Souldrift