本文整理汇总了C++中std::ofstream::write方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::write方法的具体用法?C++ ofstream::write怎么用?C++ ofstream::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ofstream
的用法示例。
在下文中一共展示了ofstream::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void
DetectorNCC::Write(std::ofstream &s, bool binary)
{
assert(binary);
int t = IOBinary::DETECTOR_NCC;
s.write((char*)&t, sizeof(t));
IOBinary::WriteMat(s, _refs);
t = _patch.size();
s.write((char*)&t, sizeof(t));
for(size_t i=0; i< _patch.size(); i++)
_patch[i].Write(s, true);
}
示例2: writeCoords
void FeatureConnector::writeCoords(std::ofstream& output_file, const std::vector<geos::geom::Coordinate>* coords, bool singleton) {
quint32 crdCount = (quint32)coords->size();
if(!singleton) {
output_file.write((char *)&crdCount,4);
}
std::vector<double> crds(crdCount * 3);
quint32 count = 0;
for(const geos::geom::Coordinate& crd : *coords) {
crds[count] = crd.x;
crds[count+1] = crd.y;
crds[count+2] = 0;
count +=3;
}
output_file.write((char *)&crds[0], crdCount * 8 * 3);
}
示例3: readsome
void readsome(const boost::system::error_code& ec, std::size_t bytes_transferred)
{
if (ec == error::eof) {
file.close();
if (!file) {
ERROR "Cannot write to file " << filename;
onerror();
} else if (filesize == 0) {
ERROR "Empty segment " << file_url.to_string();
onerror();
} else {
downloading = false;
complete = true;
auto download_duration = duration_cast<milliseconds>(steady_clock::now() - download_start).count();
INFO "Completed segment " << file_url.to_string() << " (" << std::setprecision(1) << std::fixed <<
(filesize / 1024.0 / 1024.0) << " MB) in " << download_duration <<
" ms (" << (filesize * 8000 / 1024.0 / 1024.0 / download_duration) << "Mbps)";
}
} else if (ec) {
ERROR "Error reading URL " << file_url.to_string() << ": " << ec.message();
onerror();
} else {
file.write(&buffer[0], bytes_transferred);
filesize += bytes_transferred;
segment_stream.async_read_some(boost::asio::buffer(buffer), std::bind(&Segment::readsome, this, _1, _2));
}
}
示例4: write_rat_header
void write_rat_header(std::ofstream& file, const std::vector<uint32_t>& sizes,
const uint32_t var, const uint32_t type,
const std::string& info)
{
using tools::endian_reverse_inplace;
using std::string;
auto write = [&file](uint32_t x) {
endian_reverse_inplace(x);
file.write(reinterpret_cast<const char*>(&x), sizeof(x));
};
const uint32_t dim = sizes.size();
write(dim);
for (auto sz : sizes) {
write(sz);
}
write(var);
write(type);
write(0);
write(0);
write(0);
write(0);
string _info = string(80, ' ');
boost::copy(string(info, 0, 80), _info.begin());
file << _info;
}
示例5: writePnm
void Bitmap::writePnm(std::ofstream &o) const {
o << "P5" << std::endl;
o << width << " " << height << std::endl;
o << "255" << std::endl;
o.write((const char *)buf, width * height);
o.close();
}
示例6: while
//! write sector to file
//!
//! @param file file to write to
//!
//! @return success
//!
bool
Sector::writeToH8D(std::ofstream &file)
{
uint16_t pos = 0;
// look for the sync for the header
while ((buf_m[pos] != 0xfd) && (pos < bufSize_m))
{
pos++;
}
// skip past the header, since 0xfd could be the checksum
pos += 5;
// look for the data
while ((buf_m[pos++] != 0xfd) && (pos < bufSize_m))
{ }
if ((bufSize_m - pos) < 256)
{
printf("Error data not found - sector: %d\n", sector_m);
pos = bufSize_m - 256;
}
// write out the sector
if (buf_m)
{
file.write((const char*) &buf_m[pos], 256);
}
return true;
}
示例7: main
int main(int argc, char *argv[])
{
PIN_InitSymbols();
if( PIN_Init(argc, argv))
{
return usage();
}
traceFile.open(outputFile.Value().c_str());
string trace_header = string("#\n"
"# Shellcode detector\n"
"#\n\nMAX_LEGIT_INSTRUCTION_LOG_SIZE : ") +
KnobMaxLegitInsLogSize.ValueString() + "\n\n";
for ( UINT32 i = 0; i < KnobModuleConcerned.NumberOfValues(); i++ )
{
LOG( "[+] ... " + KnobModuleConcerned.Value(i) + "\n" );
modlist.insert( KnobModuleConcerned.Value(i) );
}
traceFile.write(trace_header.c_str(), trace_header.size());
INS_AddInstrumentFunction(traceInst, 0);
PIN_AddFiniFunction(fini, 0);
// Never returns
PIN_StartProgram();
return 0;
}
示例8: gz_uncompress
static void gz_uncompress( gzFile in, std::ofstream &out ) {
char buf[2048 * 1024];
int len;
size_t bytes = 0;
for (
len = gzread( in, buf, 2048 * 1024 );
len;
len = gzread( in, buf, 2048 * 1024 )
) {
if ( len < 0 ) {
int err;
gzerror( in, &err );
// If an error occurred in the file system and not in the compression library, err is set to Z_ERRNO
if ( err == Z_ERRNO ) {
throwSystemError( errno, "Failed to read compressed file" );
} else {
throwGenericError( "Failed to read compressed file" );
}
} else {
out.write( buf, len );
bytes += len;
}
}
LOG( Debug, verbose_info ) << "Uncompressed " << bytes << " bytes";
}
示例9: write
bool compactIntArray::write(std::ofstream& fout)
{
fout.write((char*)&size, sizeof(size));
fout.write((char*)&wordsize, sizeof(wordsize));
fout.write((char*)&innersize, sizeof(innersize));
fout.write((char*)array, sizeof(*array) * innersize);
if(fout.bad())
{
return false;
}
else
{
return true;
}
}
示例10: exception
void binary_reader::stock_data::write( std::ofstream& out )
{
if ( !out.write( stock_name_, sizeof(char)*(stock_size+1) ) )
throw std::exception( "Error while writing data\n" );
int year_, month_, day_;
sscanf( date_time_, "%4d%2d%2d", &year_, &month_, &day_ );
boost::uint32_t day_time_ = 372*(year_-1) + 31*(month_-1) + day_;
if ( !out.write( reinterpret_cast<char*> (&day_time_), sizeof( boost::uint32_t ) ) )
throw std::exception( "Error while writing data\n" );
if ( !out.write( reinterpret_cast<char*> (&vwap_), sizeof(double) ) )
throw std::exception( "Error while writing data\n" );
if ( !out.write( reinterpret_cast<char*> (&volume_), sizeof( boost::uint32_t ) ) )
throw std::exception( "Error while writing data\n" );
if ( !out.write( reinterpret_cast<char*> (&f2_), sizeof(double) ) )
throw std::exception( "Error while writing data\n" );
}
示例11:
void d2o_writer::impl::write(std::ofstream & file) const
{
byte_buffer buffer;
buffer.write_bytes<false>((const uint8_t *)"D2O", 3);
buffer << 0;
std::unordered_map<int, int> offsets;
for (auto && it : _objects)
{
offsets.emplace(it.first, buffer.tellp());
buffer << it.second.first;
_classes.at(it.second.first).write(_owner, buffer, it.second.second);
}
int header = buffer.tellp();
buffer << static_cast<int>(offsets.size() * 8);
for (auto && it : offsets)
buffer << it.first << it.second;
buffer << static_cast<int>(_classes.size());
for (auto && it : _classes)
it.second.pack(buffer, it.first);
buffer.seekp(3);
buffer << header;
file.write((const char *)&buffer[0], buffer.size());
}
示例12: SaveState
void MemoryMap::SaveState(std::ofstream& ofs)
{
ofs.write((char*)_ram, sizeof(_ram));
_ppu->SaveState(ofs);
_apu->SaveState(ofs);
_mapper->SaveState(ofs);
}
示例13: writeBucketIndexSetVector
void writeBucketIndexSetVector(std::ofstream &file, const PVRTBucketIndexSetVector &indexsets)
{
const size_t size = indexsets.size();
file.write((const char*)&size, sizeof(size_t));
for (unsigned int i=0; i < size; i++)
writeBucketIndexSet(file, indexsets[i]);
}
示例14: write_pixels
void cineon_writer_t::write_pixels( std::ofstream& out, const image::const_image_view_t& view) const
{
std::vector<boost::uint32_t> buffer( view.width());
for( int y = 0; y < view.height(); ++y)
{
image::const_image_view_t::x_iterator src_it( view.row_begin( y));
for( int x = 0; x < view.width(); ++x)
{
boost::uint32_t pix = 0;
float r = boost::gil::get_color( *src_it, boost::gil::red_t());
float g = boost::gil::get_color( *src_it, boost::gil::green_t());
float b = boost::gil::get_color( *src_it, boost::gil::blue_t());
boost::uint32_t ri = adobe::clamp( r, 0.0f, 1.0f) * 1023;
boost::uint32_t gi = adobe::clamp( g, 0.0f, 1.0f) * 1023;
boost::uint32_t bi = adobe::clamp( b, 0.0f, 1.0f) * 1023;
pix = ( ri << 22) | ( gi << 12) | ( bi << 2);
buffer[x] = IECore::asBigEndian( pix);
++src_it;
}
// write vector
out.write( reinterpret_cast<char *>( &buffer[0]), view.width() * sizeof( boost::uint32_t));
if ( out.fail())
throw exception( "error while writting image");
}
}
示例15: CreatePath
void Permutator::CreatePath(Node* n, std::ofstream& gvFile)
{
std::stringstream stream;
std::string pathAttribute = "[ penwidth = 5];\n";
stream << std::hex << n->GetOffset();
std::string stateName = "\"0x" + stream.str() + "\"";
stream.str(std::string());
for (unsigned int i = 0; i < n->GetChildren().size(); ++i)
{
stream << std::hex << n->GetChildren().at(i)->GetOffset();
std::string childName = "\"0x" + stream.str() + "\"";
std::string pathValue = stateName + " -> " + childName + " " + pathAttribute;
try
{
gvFile.write(pathValue.c_str(), pathValue.length());
}
catch (std::fstream::failure e)
{
std::cerr << "CreatePath: Error while writing paths to graphviz output file: " << e.what() << std::endl;
return;
}
CreatePath(n->GetChildren().at(i), gvFile);
stream.str(std::string());
}
return;
}