本文整理汇总了C++中ostream::write方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::write方法的具体用法?C++ ostream::write怎么用?C++ ostream::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ostream
的用法示例。
在下文中一共展示了ostream::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_magic
void write_magic(ostream& os, const string& magic) {
os.write(magic.c_str(), 4);
}
示例2: WriteByteOrder
bool WriteByteOrder( ostream& o ) const { Uint8 order = 0x01234567; o.write( (const char*)&order, sizeof( order ) ); return o.good(); }
示例3: WriteData
bool WriteData( ostream& o ) const { o.write( (const char*)m_data, sizeof( *m_data ) * m_size ); return o.good(); }
示例4:
// string
void operator& (string x, ostream& stream) {
x.length() & stream;
stream.write (x.c_str(), x.length());
}
示例5: writeHoudiniStr
void writeHoudiniStr(ostream& ostream,const string& s)
{
write<BIGEND>(ostream,(short)s.size());
ostream.write(s.c_str(),s.size());
}
示例6: writeLength
void writeLength(ostream &os, short len)
{
len = htons(len);
os.write((char *)&len, sizeof(short));
}
示例7: writeToFile
void Tempo::writeToFile(ostream & output) {
MetaEvent::writeToFile(output);
output.put((char)3); // size
output.write(MidiUtil::intToBytes(mMPQN, 3), 3);
}
示例8: write
void StreamUtils::write(ostream& os, int i) {
os.write((char*) &i, sizeof(int));
}
示例9: TypeException
void aol::Vector<_DataType>::saveRaw ( ostream &out, const qc::SaveType type, const DataType Minimum, const DataType Maximum ) const {
int i = 0;
DataType maximum = Maximum;
if ( ( type == qc::PGM_UNSIGNED_CHAR_BINARY || type == qc::PGM_UNSIGNED_SHORT_BINARY ) && Maximum == 0 ) {
cerr << "Cannot scale image to a maximum of 0, scaling to 1 instead.\n";
// This is necessary to write complete black images
maximum = 1;
}
switch ( type ) {
case qc::PGM_UNSIGNED_CHAR_ASCII: {
aol::Vector<unsigned char> buffer ( this->_size );
bool flag = this->createOverflowHandledData ( buffer, Minimum, maximum );
for ( i = 0; i < this->_size; ++i ) {
out << static_cast<int> ( buffer[i] ) << " ";
if ( ( i % 10 ) == 9 ) out << std::endl;
}
if ( flag && !quietMode ) cerr << "warning: Data contains values < 0 that are converted to unsigned char\n";
}
break;
case qc::PGM_UNSIGNED_CHAR_BINARY: {
aol::Vector<unsigned char> buffer ( this->_size );
bool flag = this->createOverflowHandledData ( buffer, Minimum, maximum );
out.write ( reinterpret_cast<char*> ( buffer.getData() ), this->_size );
if ( flag && !quietMode ) cerr << "warning: Data contains values < 0 that are converted to unsigned char\n";
}
break;
case qc::PGM_FLOAT_ASCII: {
for ( i = 0; i < this->_size; ++i ) {
out << this->_pData[i] << " ";
if ( ( i % 10 ) == 9 ) out << std::endl;
}
}
break;
case qc::PGM_FLOAT_BINARY: {
if ( ( sizeof ( float ) == sizeof ( DataType ) ) && !(std::numeric_limits<DataType>::is_integer) ) {
out.write ( reinterpret_cast<char *> ( this->_pData ), this->_size * sizeof ( float ) );
} else {
float * buffer = new float[this->_size];
for ( i = 0; i < this->_size; ++i ) buffer[i] = static_cast<float> ( this->_pData[i] );
out.write ( reinterpret_cast<char *> ( buffer ), this->_size * sizeof ( float ) );
delete[] buffer;
}
}
break;
case qc::PGM_DOUBLE_BINARY: {
if ( ( sizeof ( double ) == sizeof ( DataType ) ) && !(std::numeric_limits<DataType>::is_integer) ) {
out.write ( reinterpret_cast<char *> ( this->_pData ), this->_size * sizeof ( double ) );
} else {
double * buffer = new double[this->_size];
for ( i = 0; i < this->_size; ++i ) buffer[i] = static_cast<double> ( this->_pData[i] );
out.write ( reinterpret_cast<char *> ( buffer ), this->_size * sizeof ( double ) );
delete[] buffer;
}
}
break;
case qc::PGM_UNSIGNED_SHORT_BINARY: {
bool flag = false;
unsigned short *buffer = new unsigned short[this->_size];
for ( i = 0; i < this->_size; ++i ) {
DataType temp = this->_pData[i];
if ( static_cast<double> ( temp ) < 0 ) {
flag = true;
// Workaround for icc (replaced - with abs)
temp = aol::Abs ( this->_pData[i] );
}
buffer[i] = static_cast<unsigned short> ( static_cast<double> ( temp ) / static_cast<double> ( maximum ) * 65535.0 );
}
out.write ( reinterpret_cast<char*> ( buffer ), this->_size * sizeof ( unsigned short ) );
delete[] buffer;
if ( flag && !this->quietMode ) cerr << "warning: Data contains values < 0 that are converted to unsigned short\n";
}
break;
default:
throw aol::TypeException ( "aol::Vector<DataType>::saveRaw: invalid type specified", __FILE__, __LINE__ );
}
if ( out.good() ) {
if ( !quietMode )
cerr << "Successfully wrote to PGM " << type << " stream\n";
} else {
const aol::Bzipofstream* pOut = dynamic_cast<const aol::Bzipofstream*>(&out);
if( pOut != NULL )
throw aol::Exception ( "aol::Vector<DataType>::saveRaw: Writing to aol::Bzipofstream failed. Is there enough free memory to hold the whole file?", __FILE__, __LINE__ );
else
throw aol::Exception ( "aol::Vector<DataType>::saveRaw: Error writing file", __FILE__, __LINE__ );
}
}
示例10: WriteSize
void CSRFormat::WriteSize(int size,ostream &ofs)
{
ofs.write((char*)&size,sizeof(int));
}
示例11: out
void Header::out(ostream & streamOut)
{
assert( _name[0] && _mode[0] && _uid[0] && _gid[0] && _size[0] && _mtime[0] && _magic[0] && _version[0] && _uname[0] && _gname[0] );
if (! _chksum[0]) { checksum(); }
streamOut.write((char *) this, sizeof(Header));
}
示例12: readAndWriteHeaders
void WavReader::readAndWriteHeaders(
const std::string& name,
istream& file,
ostream& out,
FormatSubchunk& formatSubchunk,
FormatSubchunkHeader& formatSubchunkHeader) {
RiffHeader header;
file.read(reinterpret_cast<char*>(&header), sizeof(RiffHeader));
// ...
if (toString(header.id, 4) != "RIFF") {
rLog(channel, "ERROR: %s is not a RIFF file",
name.c_str());
return;
}
if (toString(header.format, 4) != "WAVE") {
rLog(channel, "ERROR: %s is not a wav file: %s",
name.c_str(),
toString(header.format, 4).c_str());
return;
}
out.write(reinterpret_cast<char*>(&header), sizeof(RiffHeader));
file.read(reinterpret_cast<char*>(&formatSubchunkHeader),
sizeof(FormatSubchunkHeader));
if (toString(formatSubchunkHeader.id, 4) != "fmt ") {
rLog(channel, "ERROR: %s expecting 'fmt' for subchunk header; got '%s'",
name.c_str(),
toString(formatSubchunkHeader.id, 4).c_str());
return;
}
out.write(reinterpret_cast<char*>(&formatSubchunkHeader),
sizeof(FormatSubchunkHeader));
file.read(reinterpret_cast<char*>(&formatSubchunk), sizeof(FormatSubchunk));
out.write(reinterpret_cast<char*>(&formatSubchunk), sizeof(FormatSubchunk));
rLog(channel, "format tag: %u", formatSubchunk.formatTag); // show as hex?
rLog(channel, "samples per second: %u", formatSubchunk.samplesPerSecond);
rLog(channel, "channels: %u", formatSubchunk.channels);
rLog(channel, "bits per sample: %u", formatSubchunk.bitsPerSample);
auto bytes = formatSubchunkHeader.subchunkSize - sizeof(FormatSubchunk);
auto additionalBytes = new char[bytes];
file.read(additionalBytes, bytes);
out.write(additionalBytes, bytes);
FactOrData factOrData;
file.read(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData));
out.write(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData));
if (toString(factOrData.tag, 4) == "fact") {
FactChunk factChunk;
file.read(reinterpret_cast<char*>(&factChunk), sizeof(FactChunk));
out.write(reinterpret_cast<char*>(&factChunk), sizeof(FactChunk));
file.read(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData));
out.write(reinterpret_cast<char*>(&factOrData), sizeof(FactOrData));
rLog(channel, "samples per channel: %u", factChunk.samplesPerChannel);
}
if (toString(factOrData.tag, 4) != "data") {
string tag{toString(factOrData.tag, 4)};
rLog(channel, "%s ERROR: unknown tag>%s<", name.c_str(), tag.c_str());
return;
}
}
示例13: Write
int FixedTextBuffer::Write(ostream & stream) {
stream.write(Buffer, BufferSize);
return stream.good();
}
示例14: writeTo
//--------------------------------------------------
bool ofBuffer::writeTo(ostream & stream) const{
if( stream.bad() ) return false;
stream.write(&(buffer[0]),buffer.size()-1);
return true;
}
示例15: Write
int DelimTextBuffer::Write(ostream & stream) const{
stream.write((char*) &bufferSize, sizeof(bufferSize));
stream.write(buffer, bufferSize);
return stream.good();
}