本文整理汇总了C++中std::fstream类的典型用法代码示例。如果您正苦于以下问题:C++ fstream类的具体用法?C++ fstream怎么用?C++ fstream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了fstream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveContextSettingsToFile
bool Context::saveContextSettingsToFile( std::fstream &file ) const{
if( !file.is_open() ){
errorLog << "saveContextSettingsToFile(fstream &file) - The file is not open!" << std::endl;
return false;
}
if( !MLBase::saveBaseSettingsToFile( file ) ) return false;
file << "Initialized: " << initialized << std::endl;
return true;
}
示例2: new
MemoryAccessor::MemoryAccessor( GsTLInt size, std::fstream& stream ) {
values_ = new(std::nothrow) float[size];
flags_ = new(std::nothrow) bool[size];
if(values_ == NULL || flags_ == NULL) size_ = 0;
else {
size_ = size;
if( !stream.is_open() ) {
GsTLlog << "Error: Stream not open when trying to swap property to memory!!"
<< gstlIO::end;
}
stream.seekg(0);
long int remaining = size*sizeof( float );
stream.read( (char*) values_, remaining );
// read the flags
remaining = size*sizeof( bool );
stream.read( (char*) flags_, remaining );
}
}
示例3: unpatch
bool unpatch(std::fstream &file, char* buffer, size_t size)
{
std::vector<size_t> regemu;
find_all(buffer, "REGEMU32", size, 8, regemu);
if (!regemu.empty())
{
for (size_t pos : regemu)
{
file.seekg(pos, std::ios::beg);
file.write("ADVAPI32", 8);
}
wprintf(L"REGEMU32 found (%d) and unpatched. ", regemu.size());
}
else
{
wprintf(L"REGEMU32 not found. ");
}
return !regemu.empty();
}
示例4: search_forward
std::streampos search_forward ( std::fstream & _bs, const std::string & sample )
{
size_t match ( 0 );
cSaveIStreamPosition ip ( &_bs );
streampos result ( static_cast<streampos>( -1 ) );
cSaveStreamExceptions se ( &_bs, std::ios_base::goodbit );
for( int ch( EOF ); match < sample.length(); match++ )
{
ch = _bs.get();
if( ch == EOF )
break;
else if( ch != sample[match] )
match = 0;
}
if( match == sample.length() )
result = _bs.tellg() - static_cast<streampos>( match );
_bs.clear();
return result;
}
示例5: save
bool ClassLabelChangeFilter::save( std::fstream &file ) const {
if( !file.is_open() ){
errorLog << "save(fstream &file) - The file is not open!" << std::endl;
return false;
}
file << "GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" << std::endl;
file << "NumInputDimensions: " << numInputDimensions << std::endl;
file << "NumOutputDimensions: " << numOutputDimensions << std::endl;
return true;
}
示例6: write_var
void write_var(std::fstream &stream, T variable)
{
static_assert(std::is_signed<T>::value == false, "Value must be unsigned");
constexpr const BYTE ZERO_BITTED = std::numeric_limits<BYTE>::max() / 2;
constexpr const BYTE ONE_BITTED = ZERO_BITTED + 1;
loop:
{
if ((variable & ~ZERO_BITTED) == 0)
{
stream.put(static_cast<BYTE>(variable));
return;
}
else
{
stream.put(static_cast<BYTE>((variable & ZERO_BITTED) | ONE_BITTED));
variable >>= 7;
}
}
goto loop;
}
示例7: ReadElectricField
inline void ReadElectricField(std::fstream& field_file) {
std::string line;
assert(field_file.is_open());
getline(field_file, line);
const std::vector<std::string> split_line = Split(line, ' ');
std::vector<std::string>::const_iterator i_split = split_line.begin();
for (int i_atom = 0; i_atom < group_size_; i_atom++) {
for (int i_dim = 0; i_dim < DIMS; i_dim++) {
electric_fields_(i_atom,i_dim) = atof((*i_split).c_str());
i_split++;
}
}
}
示例8: load
bool RBMQuantizer::load( std::fstream &file ){
//Clear any previous model
clear();
if( !file.is_open() ){
errorLog << "load(fstream &file) - The file is not open!" << std::endl;
return false;
}
std::string word;
//First, you should read and validate the header
file >> word;
if( word != "RBM_QUANTIZER_FILE_V1.0" ){
errorLog << "load(fstream &file) - Invalid file format!" << std::endl;
return false;
}
//Second, you should load the base feature extraction settings to the file
if( !loadFeatureExtractionSettingsFromFile( file ) ){
errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
return false;
}
file >> word;
if( word != "QuantizerTrained:" ){
errorLog << "load(fstream &file) - Failed to load QuantizerTrained!" << std::endl;
return false;
}
file >> trained;
file >> word;
if( word != "NumClusters:" ){
errorLog << "load(fstream &file) - Failed to load NumClusters!" << std::endl;
return false;
}
file >> numClusters;
if( trained ){
if( !rbm.load( file ) ){
errorLog << "load(fstream &file) - Failed to load SelfOrganizingMap settings from file!" << std::endl;
return false;
}
initialized = true;
featureDataReady = false;
quantizationDistances.resize(numClusters,0);
}
return true;
}
示例9: 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);
}
示例10: printFile
void printFile(std::fstream &file, const char filename[]) {
file.seekg(0, file.end);
int fileSize = file.tellg();
contact contacts[ROWS_TOTAL_COUNT];
std::ifstream fileToRead;
fileToRead.open(filename, std::ios::binary | std::ios::in);
if (fileToRead.fail()) {
std::cout << "Не удается открыть файл\n";
exit(1);
}
fileToRead.seekg(0, fileToRead.beg);
bool formatError = false;
std::cout << std::endl << "***************** Prinitng file ****************" << std::endl << std::endl;
for (int i = 0; i < fileSize / ROW_LENGTH; i++) {
fileToRead.read(contacts[i].firstName, NAME_LENGTH);
fileToRead.read(contacts[i].lastName, NAME_LENGTH);
fileToRead.read(contacts[i].phone, PHONE_LENGTH);
std::cout << std::setw(NAME_LENGTH) << contacts[i].firstName << " | ";
std::cout << std::setw(NAME_LENGTH) << contacts[i].lastName << " | ";
std::cout << contacts[i].phone << std::endl;
if (contacts[i].phone[1] != '(' || contacts[i].phone[5] != ')' || contacts[i].phone[9] != '-') {
formatError = true;
}
}
std::cout << std::endl << "***************** end of file ******************" << std::endl << std::endl;
std::cout << "Length of the file should be " << ROW_LENGTH * ROWS_TOTAL_COUNT << ", got " << fileSize << std::endl;
if (!formatError) {
std::cout << "Correct formatting" << std::endl;
}
else {
std::cout << "Error: incorrect formatting" << std::endl;
}
fileToRead.close();
}
示例11: 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);
}
}
示例12: loadModelFromFile
bool ClassLabelFilter::loadModelFromFile( std::fstream &file ){
if( !file.is_open() ){
errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
return false;
}
std::string word;
//Load the header
file >> word;
if( word != "GRT_CLASS_LABEL_FILTER_FILE_V1.0" ){
errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
return false;
}
file >> word;
if( word != "NumInputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
return false;
}
file >> numInputDimensions;
//Load the number of output dimensions
file >> word;
if( word != "NumOutputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
return false;
}
file >> numOutputDimensions;
//Load the minimumCount
file >> word;
if( word != "MinimumCount:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read MinimumCount header!" << std::endl;
return false;
}
file >> minimumCount;
file >> word;
if( word != "BufferSize:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read BufferSize header!" << std::endl;
return false;
}
file >> bufferSize;
//Init the classLabelFilter module to ensure everything is initialized correctly
return init(minimumCount,bufferSize);
}
示例13: setProgName
// sets the prog name. Requires a file pointer. Extracts exactly six characters
// from fstream
void HeaderRecord::setProgName(std::fstream & file) {
int i;
// get 6 characters and append them to the progName string
for (i = 0; i < 6; i++) {
// needs a string argument for append()
char tempChar = file.get();
// error handler, check for eof bit
Record::unexpectedEOF(file);
// append to string
progName += tempChar;
}
std::cout << "Program name: " + progName;
}
示例14: ReadFrom
/// Reads from file stream.
void Tile::ReadFrom(std::fstream & file){
// Read version
int version;
file.read((char*)&version, sizeof(int));
assert(tileVersion == version);
// Read type
file.read((char*)&typeIndex, sizeof(int));
// Read position.
position.ReadFrom(file);
// Write stuff bound to the tile.
int stuff = 0;
file.read((char*)&stuff, sizeof(int));
// If got event
if (stuff & 0x001){
// Load event source
event = new Script();
event->source.ReadFrom(file);
// Load it straight away, or...?
}
// Write description of additional details to file.
description.WriteTo(file);
}
示例15: loadModelFromFile
bool ClassLabelTimeoutFilter::loadModelFromFile( std::fstream &file ){
if( !file.is_open() ){
errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
return false;
}
std::string word;
//Load the header
file >> word;
if( word != "GRT_CLASS_LABEL_TIMEOUT_FILTER_FILE_V1.0" ){
errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
return false;
}
file >> word;
if( word != "NumInputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
return false;
}
file >> numInputDimensions;
//Load the number of output dimensions
file >> word;
if( word != "NumOutputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
return false;
}
file >> numOutputDimensions;
//Load the filterMode
file >> word;
if( word != "FilterMode:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read FilterMode header!" << std::endl;
return false;
}
file >> filterMode;
file >> word;
if( word != "TimeoutDuration:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read TimeoutDuration header!" << std::endl;
return false;
}
file >> timeoutDuration;
//Init the classLabelTimeoutFilter module to ensure everything is initialized correctly
return init(timeoutDuration,filterMode);
}