本文整理汇总了C++中std::iostream::write方法的典型用法代码示例。如果您正苦于以下问题:C++ iostream::write方法的具体用法?C++ iostream::write怎么用?C++ iostream::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::iostream
的用法示例。
在下文中一共展示了iostream::write方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
void SkillLevelEvent::save( std::iostream& ios )
{
Event::save(ios);
// Save bonus
ios.write( (char*) &bonus, sizeof( bonus ) );
// Save skill
ios.write( (char*) &skill, sizeof( skill ) );
}
示例2: toFile
void Ammo::toFile( std::iostream& outFile )
{
// Write Item base information:
Item::toFile( outFile );
// Write char form
outFile.write( (char*) &form, sizeof(form) );
// Write bool fired
outFile.write( (char*) &fired, sizeof(fired) );
}
示例3: loadFile
void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
{
out.clear(std::ios::goodbit);
if(m_hasSearchPath) {
std::string fullPath = resolvePath(fileName);
PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
if(!file) {
out.clear(std::ios::failbit);
stdext::throw_exception(stdext::format("failed to load file '%s': %s", fullPath.c_str(), PHYSFS_getLastError()));
} else {
int fileSize = PHYSFS_fileLength(file);
if(fileSize > 0) {
std::vector<char> buffer(fileSize);
PHYSFS_read(file, (void*)&buffer[0], 1, fileSize);
out.write(&buffer[0], fileSize);
} else
out.clear(std::ios::eofbit);
PHYSFS_close(file);
out.seekg(0, std::ios::beg);
}
} else {
std::ifstream fin(fileName);
if(!fin) {
out.clear(std::ios::failbit);
stdext::throw_exception(stdext::format("failed to load file '%s': %s", fileName.c_str(), PHYSFS_getLastError()));
} else {
out << fin.rdbuf();
}
}
}
示例4: toFile
void Fluid::toFile( std::iostream& outFile )
{
// Write Item base information:
Item::toFile( outFile );
// Write materialClass f_material
outFile.write( (char*) &f_material, sizeof(f_material) );
}
示例5: readExactly
void readExactly(size_t toread, std::iostream& result)
{
size_t hasread = 0;
while(toread > hasread && std::cin.good()) {
char a[1];
std::cin.read(a,1);
result.write(a,1);
hasread++;
}
}
示例6: print
void FilePiece::print(int64_t from, int64_t to, std::iostream &outStream)
{
if (fileData)
{
const int64_t BUFFSIZE = 8192;
int64_t targetLength;
uint8_t buffer[BUFFSIZE];
for (int64_t i = from; i <= to; i += targetLength)
{
targetLength = MIN(BUFFSIZE, to - i + 1);
cs.read(buffer, i, targetLength);
outStream.write((const char *)buffer, targetLength);
}
}
else
{
if (signature == SIG_CDFH || signature == SIG_DD)
{
FilePiece* fileDataPiece = (FilePiece*)extraBuffer;
if (fileDataPiece->cs.reachedOffset < (fileDataPiece->length - 1))
{
uint8_t tmp;
fileDataPiece->cs.read(&tmp, fileDataPiece->length - 1, 1);
}
if (fileDataPiece->cs.reachedOffset < (int64_t)(fileDataPiece->length - 1)) //safety measure: insufficient crc
abort();
if (signature == SIG_CDFH)
((CDFH*)buffer)->CRC32 = fileDataPiece->cs.crc.GetCRC32();
else if (signature == SIG_DD)
((DD*)buffer)->CRC32 = fileDataPiece->cs.crc.GetCRC32();
}
outStream.write((const char *)buffer + from, to - from + 1);
}
}
示例7: test_seekable_in_chunks
bool test_seekable_in_chunks(std::iostream& io)
{
int i; // old 'for' scope workaround.
// Test seeking with ios::cur
for (i = 0; i < data_reps; ++i) {
io.write(narrow_data(), chunk_size);
io.seekp(-chunk_size, BOOST_IOS::cur);
char buf[chunk_size];
io.read(buf, chunk_size);
if (strncmp(buf, narrow_data(), chunk_size) != 0)
return false;
io.seekp(-chunk_size, BOOST_IOS::cur);
io.write(narrow_data(), chunk_size);
}
// Test seeking with ios::beg
std::streamoff off = 0;
io.seekp(0, BOOST_IOS::beg);
for (i = 0; i < data_reps; ++i, off += chunk_size) {
io.write(narrow_data(), chunk_size);
io.seekp(off, BOOST_IOS::beg);
char buf[chunk_size];
io.read(buf, chunk_size);
if (strncmp(buf, narrow_data(), chunk_size) != 0)
return false;
io.seekp(off, BOOST_IOS::beg);
io.write(narrow_data(), chunk_size);
}
// Test seeking with ios::end
io.seekp(0, BOOST_IOS::end);
off = io.tellp();
io.seekp(-off, BOOST_IOS::end);
for (i = 0; i < data_reps; ++i, off -= chunk_size) {
io.write(narrow_data(), chunk_size);
io.seekp(-off, BOOST_IOS::end);
char buf[chunk_size];
io.read(buf, chunk_size);
if (strncmp(buf, narrow_data(), chunk_size) != 0)
return false;
io.seekp(-off, BOOST_IOS::end);
io.write(narrow_data(), chunk_size);
}
return true;
}