当前位置: 首页>>代码示例>>C++>>正文


C++ fstream::write方法代码示例

本文整理汇总了C++中std::fstream::write方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::write方法的具体用法?C++ fstream::write怎么用?C++ fstream::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::fstream的用法示例。


在下文中一共展示了fstream::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WriteSector

void WriteSector(char* buffer, size_t sec) {
    sec += partitionOffset;
    if (sec > partitionLength)
        return;

    if ((sec * 512) > fsize) {
        std::cout << "WOAH BRO THIS SECTOR IS WRONG: " << sec << std::endl;
        return;
    }

    f.seekp(sec * 512, std::ios::beg);
    f.write(buffer, 512);
}
开发者ID:Rohansi,项目名称:LoonyOS,代码行数:13,代码来源:main.cpp

示例2: WriteHeader

void PEObject::WriteHeader(std::fstream &stream)
{
    unsigned zero = 0;
    for (int i =0; i < name.size() && i < 8; i++)
        stream.write(&name[i], 1);
    for (int i = name.size(); i < 8; i++)
        stream.write((char *)&zero, 1);
    unsigned msize = ObjectAlign(objectAlign, size);
    stream.write((char *)&msize, 4);
    stream.write((char *)&virtual_addr, 4);
    msize = ObjectAlign(fileAlign, initSize);
    stream.write((char *)&msize, 4);
    stream.write((char *)&raw_addr, 4);
    stream.write((char *)&zero, 4);
    stream.write((char *)&zero, 4);
    stream.write((char *)&zero, 4);
    int flg = (flags ^ WINF_NEG_FLAGS) & WINF_IMAGE_FLAGS; /* get characteristice for section */
    stream.write((char *)&flg, 4);
}
开发者ID:doniexun,项目名称:OrangeC,代码行数:19,代码来源:PEObject.cpp

示例3: SaveLuaTable

void LuaHistoryFile::SaveLuaTable(lua_State* luaState, int nIndex, size_t nBufferLen, std::fstream& fileStream)
{
	vector<string> vecStrings;
	if(lua_istable(luaState,nIndex))
	{
		int nStrCnt = lua_objlen(luaState,nIndex);
		const char* cszWrite = NULL;
		for(int ix = 1; ix <= nStrCnt; ++ix)
		{
			lua_rawgeti(luaState, nIndex , ix);
			if(lua_isstring(luaState, -1))
			{
				cszWrite = luaL_checkstring(luaState, -1);
				wstring wstrWrite;
				UTF8_to_Unicode(cszWrite, strlen(cszWrite), wstrWrite);
				string astrWrite;
				wstrWrite += WCHAR('\n');
				Unicode_to_ANSI(wstrWrite.c_str(), wstrWrite.size(),astrWrite);
				vecStrings.push_back(astrWrite);
				
			}
			lua_pop(luaState,1);
		}
	}
	char szStrCnt[100];
	itoa(vecStrings.size(), szStrCnt, 100);
	int nStrCntLen = strlen(szStrCnt);
	szStrCnt[nStrCntLen] = '\n';
	fileStream.write(szStrCnt, nStrCntLen + 1);
	for(size_t ix = 0; ix < vecStrings.size(); ++ix)
	{
		const char* buf = vecStrings[ix].c_str();
		size_t buflen = vecStrings[ix].size();
		fileStream.write(buf, buflen);
		
	}
	
}
开发者ID:fanliaokeji,项目名称:lvdun,代码行数:38,代码来源:HistroyFile.cpp

示例4: WriteTo

/// Writes to file stream.
void Tile::WriteTo(std::fstream & file)
{
	// Write version
	file.write((char*)&tileVersion, sizeof(int));
	// Fetch type index.
	this->typeIndex = -1;
	if (type)
		typeIndex = type->type;
	// Write type index
	file.write((char*)&typeIndex, sizeof(int));
	// Write position.
	position.WriteTo(file);
	// Write stuff bound to the tile.
	int stuff = 0;
	if (event)
		stuff |= 0x001;
	file.write((char*)&stuff, sizeof(int));
	// Write the path to the source of the event.
	if (event)
		event->source.WriteTo(file);
	// Write description of additional details to file.
	description.WriteTo(file);
}
开发者ID:erenik,项目名称:engine,代码行数:24,代码来源:Tile.cpp

示例5: writeUNPW

int User::writeUNPW(std::fstream &fout){
	if (!fout.is_open()){
		fout.open("UNPW.bin", std::ios::out, std::ios::binary);
	}
	auto fpos = fout.cur;
	fout.seekp(0, fout.beg);
	encode(username);
	encode(password);
	fout.write((char*)&username, sizeof(str));
	fout.write((char*)&password, sizeof(str));
	decode(username);
	decode(password);
	fout.seekp(0, fpos);
	return 0;
}
开发者ID:shengyang998,项目名称:Libarary-system,代码行数:15,代码来源:user.cpp

示例6: Store

void Transaction::Store(std::fstream &stream)
{
	m_Date.Store(stream);
	StoreString(m_Description, stream);
	StoreString(m_Payee, stream);
	StoreString(m_Category, stream);
	m_Amount.Store(stream);
	
	stream.write((char *) &m_Type, sizeof(unsigned char));
	
	std::bitset<8> localset;	
	localset[0] = m_Cleared;
	localset[1] = m_Split;
	localset[2] = m_Reconciled;
	localset[3] = m_Flagged;
	localset[4] = m_HasFITID;
	
	unsigned char cBitset = static_cast<unsigned char>(localset.to_ulong());
	stream.write((char *) &cBitset, sizeof(unsigned char));
	
	if (m_HasFITID)
	{
		StoreString(m_FITID, stream);
	}
	
	unsigned char numSplits = static_cast<unsigned char>(m_aSplits.size());
	stream.write((char *) &numSplits, sizeof(unsigned char));
	
	std::vector<SplitTransaction>::iterator it = m_aSplits.begin();
	std::vector<SplitTransaction>::iterator itEnd = m_aSplits.end();
	
	for (; it != itEnd; ++it)
	{
		(*it).Store(stream);
	}
}
开发者ID:emiscience,项目名称:Stash,代码行数:36,代码来源:transaction.cpp

示例7:

	Database::Database(char* file) {
		backing.open(file, std::ios::in|std::ios::out|std::ios::binary);
		if (backing.eof()) {
			char ver = FIDBVER;
			backing.write(&ver, 1);
		} else {
			char usedver = '\0';
			backing.read(&usedver, 1);
			if (usedver != FIDBVER) {
				std::cerr << "Version " << usedver << " in file differs from " << FIDBVER << " in library!" << std::endl;
				return;
			}
		}
		indexstore = _ReadIndex(1); //Index is always on second byte
	}
开发者ID:ChlorideCull,项目名称:FIDB,代码行数:15,代码来源:database.cpp

示例8: _GetLock

	void Database::_GetLock(uint64_t blockpos, bool readonly) {
		char blocklock = 1;
		backing.seekg(blockpos);
		backing.read(&blocklock, 1);
		while (blocklock == 1)
		{
			std::this_thread::sleep_for(std::chrono::milliseconds(50)); //Thanks StackOverflow!
			backing.seekg(blockpos);
			backing.read(&blocklock, 1);
		}
		if (readonly) {
			blocklock = 1;
			backing.seekp(blockpos);
			backing.write(&blocklock, 1);
		}
	}
开发者ID:ChlorideCull,项目名称:FIDB,代码行数:16,代码来源:database.cpp

示例9: RawWrite

exp bool RawWrite(const char* fname, size_t offsetIn, size_t offset, size_t len) {
    std::ifstream in(fname, std::ios::in | std::ios::binary);
    if (!in.is_open())
        return false;

    // Seek to proper offsets
    in.seekg(offsetIn, std::ios::beg);
    f.seekp(offset + partitionOffset * 512, std::ios::beg);

    // Read data
    char* buffer = new char[len];
    in.read(buffer, len);
    f.write(buffer, len);

    delete[] buffer;
    in.close();

    return true;
}
开发者ID:Rohansi,项目名称:LoonyOS,代码行数:19,代码来源:main.cpp

示例10: patch

bool patch(std::fstream &file, char* buffer, size_t size)
{
	std::vector<size_t> advapi;
	find_all(buffer, "ADVAPI32", size, 8, advapi);

	std::vector<int> functionlist;

	bool fullcheck = false;
	bool supported = true;

	if (!advapi.empty())
	{
		if (fullcheck) for (int i = 0; i < 806; i++)
		{
			size_t func_len = strlen(Advapi_Function[i]);

			if (find_single(buffer, Advapi_Function[i], size, func_len))
			{
				functionlist.push_back(i);
				supported = supported && Advapi_Support[i];
			}
		};

		if (supported)
		{
			for (size_t pos : advapi)
			{
				file.seekg(pos, std::ios::beg);
				file.write("REGEMU32", 8);
			}
		}

		wprintf(L"ADVAPI32 found (%d) and patched. ", advapi.size());
	}
	else
	{
		wprintf(L"ADVAPI32 not found. ");
	}

	return !advapi.empty();
}
开发者ID:KrossX,项目名称:RegEmu32,代码行数:41,代码来源:Patcher.cpp

示例11: WriteFile

//******************************************************************************************************************************************************
//******************************************************************************************************************************************************
int WriteFile(std::fstream& fileHandle, BOOL* fieldSelections, int extractionMode, double* modeParameters, int numModeParameters, int numRecs, const mxArray *prhs[], int prhsIndex)
{
    EventRec buf;
    memset(&buf, 0, mRecordSize );
    int index = 0;

    for( int i = 0; i < numRecs; i++ ) {

        index = 0;
        if( fieldSelections[IndexTimestamp] ) {
            buf.qwTimeStamp = (unsigned __int64)(mInputFields[index][i]);
            index++;
        }

        if( !mGeneralOps.ValidRecToExtract(i, buf.qwTimeStamp, extractionMode, modeParameters, numModeParameters) ) {
            continue;
        }

        if( fieldSelections[IndexEventId] ) {
            buf.nevent_id = (short)(mInputFields[index][i]);
            index++;
        }
        if( fieldSelections[IndexTtl] ) {
            buf.nttl = (short)(mInputFields[index][i]);
            index++;
        }
        if( fieldSelections[IndexExtras] ) {
            for( int j = 0; j < EVENT_NUM_EXTRAS; j++) {
                buf.dnExtra[j] = (__int32)(mInputFields[index][(i*EVENT_NUM_EXTRAS)+j]);
            }
            index++;
        }
        if( fieldSelections[IndexEventString] ) {
            memset( buf.EventString, 0, sizeof(char)*NLX_EventRecStringSize);
            mxGetString( mxGetCell( prhs[prhsIndex], i ), buf.EventString, NLX_EventRecStringSize );
        }

        fileHandle.write( (const char*)&buf, mRecordSize );
    }
    return(Nlx2MatOK);
}
开发者ID:rajatsaxena,项目名称:IISc_Neuroscience,代码行数:43,代码来源:Mat2NlxEV.cpp

示例12: push_back

	void push_back(uint8_t x)
    {
        m_write_buf[m_widx] = x;
        if (m_sync) {
            m_read_buf[m_widx] = x;
        }
        ++m_widx;
        if (m_widx == m_buffer_size) {
            if (!m_sync) { // if not sync, write block to disk
                if (!m_stream.is_open()) {
                    m_stream.open(m_file_name,
                                  std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc);
                }
                m_stream.seekp(m_buffer_size * (m_wb++), std::ios::beg);
                m_stream.write((char*)m_write_buf, m_buffer_size);
                ++m_disk_buffered_blocks;
            }
            m_sync = 0;
            m_widx = 0;
        }
    }
开发者ID:olydis,项目名称:sdsl-lite,代码行数:21,代码来源:construct_lcp_helper.hpp

示例13: sizeof

void ssolver::Statedef::checkpoint(std::fstream & cp_file)
{
    cp_file.write((char*)&pTime, sizeof(double));
    cp_file.write((char*)&pNSteps, sizeof(uint));

	SpecdefPVecCI s_end = pSpecdefs.end();
	for (SpecdefPVecCI s = pSpecdefs.begin(); s != s_end; ++s) {
        (*s)->checkpoint(cp_file);
    }

	CompdefPVecCI c_end = pCompdefs.end();
	for (CompdefPVecCI c = pCompdefs.begin(); c != c_end; ++c) {
        (*c)->checkpoint(cp_file);
    }

	PatchdefPVecCI p_end = pPatchdefs.end();
	for (PatchdefPVecCI p = pPatchdefs.begin(); p != p_end; ++p) {
        (*p)->checkpoint(cp_file);
    }

	DiffBoundarydefPVecCI db_end = pDiffBoundarydefs.end();
	for (DiffBoundarydefPVecCI db = pDiffBoundarydefs.begin(); db != db_end; ++db) {
        (*db)->checkpoint(cp_file);
    }

	ReacdefPVecCI r_end = pReacdefs.end();
	for (ReacdefPVecCI r = pReacdefs.begin(); r != r_end; ++r) {
        (*r)->checkpoint(cp_file);
    }

	SReacdefPVecCI sr_end = pSReacdefs.end();
	for (SReacdefPVecCI sr = pSReacdefs.begin(); sr != sr_end; ++sr) {
        (*sr)->checkpoint(cp_file);
    }

	DiffdefPVecCI d_end = pDiffdefs.end();
	for (DiffdefPVecCI d = pDiffdefs.begin(); d != d_end; ++d) {
        (*d)->checkpoint(cp_file);
    }
}
开发者ID:Fandekasp,项目名称:steps,代码行数:40,代码来源:statedef.cpp

示例14: sizeof

void
CBOLoader::_writeOctreeByMat(OctreeByMatScene *aScene, std::fstream &f) {

	/* Write the bounding box */
	BoundingBox& aBoundingVolume = (BoundingBox &)aScene->getBoundingVolume();
	std::vector<vec3> &points = aBoundingVolume.getNonTransformedPoints();
	float flo[6];
	flo[0] = points[0].x;
	flo[1] = points[0].y;
	flo[2] = points[0].z;
	flo[3] = points[1].x;
	flo[4] = points[1].y;
	flo[5] = points[1].z;
	f.write(reinterpret_cast<char*> (flo), 6 * sizeof(float));

	OctreeByMat *o = aScene->m_pGeometry;
	_writeString(o->getName(),f);

	std::shared_ptr<OctreeByMatNode> &n = o->m_pOctreeRootNode;

	_writeOctreeByMatNode(n,f);
}
开发者ID:,项目名称:,代码行数:22,代码来源:

示例15: WriteLn

// WriteLn
// Writes the formatted output to the file stream, returning the number of
// bytes written.
int WriteLn(std::fstream& stream, const char* fmt, ...)
{
   char buf[MAX_BUFFER_LEN];
   int nLength;
   t_Str szMsg;

   memset(buf, 0, MAX_BUFFER_LEN);
   va_list args;

   va_start (args, fmt);
   nLength = vsnprintf(buf, MAX_BUFFER_LEN, fmt, args);
   va_end (args);


   if ( buf[nLength] != '\n' && buf[nLength] != '\r' )
      buf[nLength++] = '\n';


   stream.write(buf, nLength);

   return nLength;
}
开发者ID:BackupTheBerlios,项目名称:btg-svn,代码行数:25,代码来源:cdatafile.cpp


注:本文中的std::fstream::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。